The problem with that is that exec() doesn't return the return value of the command, which I needed for this particular thing. What I wanted was 'system(string command)' and I can get everything else I need out of $?.
The return value is the exit status of the program as returned by the "wait" call. To get the actual exit value, shift right by eight (see below). See also "exec". This is not what you want to use to capture the output from a command, for that you should use merely backticks or "qx//", as described in "`STRING`" in perlop. Return value of -1 indicates a failure to start the program or an error of the wait(2) system call (inspect $! for the reason).
There's some irony in me saying function not elegance, because one of my big improvements in the code I wrote (and I'm talking, it cut out 30% of the processing time) involved simplifying logic and taking out redundant code by making a few more globals. (Globals are bad, but a statement that's calculated about 500 times PER iteration and doesn't change because it's all constants-for-the-iteration is even worse.)
The best part was ... my director was the guy who wrote the original code, which I didn't know, and I was criticizing it to my mentor/or whatever you call him, and my director was standing there and said "heh, I wrote that." ... I ended up stammering something about the fact that none of us are really programmers, so these things happen. (And they do. Frequently.)
Then again, maybe it's not ironic; I consider processing time to be functional, not elegant, because it impacts the amount of time before you can do anything with the results.
Isn't string exec (string command [, string array [, int return_var]]) the function for executing a command?
Reply
Reply
by the "wait" call. To get the actual exit value, shift right
by eight (see below). See also "exec". This is not what you
want to use to capture the output from a command, for that you
should use merely backticks or "qx//", as described in
"`STRING`" in perlop. Return value of -1 indicates a failure
to start the program or an error of the wait(2) system call
(inspect $! for the reason).
Reply
But I'm not a programmer (I just want to get the job done, not make it elegant) :p
Reply
Reply
The best part was ... my director was the guy who wrote the original code, which I didn't know, and I was criticizing it to my mentor/or whatever you call him, and my director was standing there and said "heh, I wrote that." ... I ended up stammering something about the fact that none of us are really programmers, so these things happen. (And they do. Frequently.)
Then again, maybe it's not ironic; I consider processing time to be functional, not elegant, because it impacts the amount of time before you can do anything with the results.
Reply
Leave a comment