in reply to Re: Re: system & shell metacharacters
in thread system & shell metacharacters

open BAR, '|bar.pl' || die qq(Useful msg: $!);

... is wrong, because it is interpreted as:

open BAR, ('|bar.pl' || die qq(Useful msg: $!));

... so remember to use "or die" rather than "|| die".

Replies are listed 'Best First'.
Re: Re: Re: Re: system & shell metacharacters
by snax (Hermit) on Jul 23, 2003 at 16:39 UTC
    Really? Ya learn something new every day :) I have a great number of scripts to modify, it would seem....
      Using || die is fine as long as parens are used.
      open(FOO, $file) || die "Couldn't open $file - $!\n";

      When no parens are present, you should use or die instead.

      Personally, I always use parens everywhere so my code is littered with || dies.

      -- vek --
        I'm just surprised that I've never seen a problem using it exactly as I've written it above, which I do with great regularity. The docs say that the calling signatures are
        open FILEHANDLE, EXPR
        and
        open FILEHANDLE
        My syntax falls into the first case, but what constitutes an "EXPR"? I've got a string, the || operator, then the die -- does that qualify as an EXPR? I'll have to poke around the docs some more.....

        Oh. Playing around with the right and wrong way shows me that my "|| die" syntax fails without die-ing.