Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Re: vanishing system call

by sauoq (Abbot)
on Sep 20, 2002 at 19:57 UTC ( [id://199608]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: vanishing system call
in thread vanishing system call

system(" cat $file | sort -t\\| +1 -2 > $file.out ") || die "can't sort the file: $!";

Generally, system will return 0 when it succeeds not when it fails. That code would die everytime the system call worked.

Update: As ChemBoy points out in his reply, $! is not what you want to look at. As I pointed out in a reply to another post of ChemBoy's, it only makes sense to look at $! when system returns -1 meaning that the command was not executed. This doesn't change the advice above.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Error trapping from system
by ChemBoy (Priest) on Sep 20, 2002 at 22:37 UTC

    Nice catch on the return value of system--but in error cases, it doesn't set $!, but rather $?. Unfortunately, $? doesn't stringify nearly as nicely as $!, but you can get reasonable information (as outlined in perlvar) with a little extra work:

    unless (0 == system $cmd) { warn sprintf "External command '%s' failed with exit status %d (sig +nal %d). A core dump %s\n", $cmd, $? >> 8, $? & 127, $? & 128 ? "occurred" : "did not occur"; }



    If God had meant us to fly, he would *never* have given us the railroads.
        --Michael Flanders

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://199608]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-24 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found