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