in reply to Re: open failure code
in thread open failure code

You could also use this type of contruct

open(FH,"<".$log) ? print "opened\n" : print "unable to open $!\n";
it's not any better at all just making you aware of another option.


Replies are listed 'Best First'.
Re: Re: Re: open failure code
by jweed (Chaplain) on Nov 27, 2003 at 02:50 UTC
    Though this works, the ternary operator, like the grep and map operators, should not really be use in void context.
    if (open(FH,"<".$log) { print "opened\n"; } else { print "unable to open $!\n"; }
    is preferred.

    Who is Kayser Söze?
      Of course the same could be done just with proper logical short circuit operators. Prefer the low-precedence ones for this sort of thing:

      open FH, "<", $log and print "Success\n" or print "Failure\n";

      That avoids trinaries and if/else's.


      "If I had my life to live over again, I'd be a plumber." -- Albert Einstein