Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: open failure code

by Anonymous Monk
on Nov 26, 2003 at 23:38 UTC ( [id://310419]=note: print w/replies, xml ) Need Help??


in reply to open failure code

What all these wise monks forgot to tell you is how they arrived at the answer :)
perl -MO=Deparse,-p $down="false"; open (FH, $log) || $down = "true"; __END__ Can't modify logical or (||) in scalar assignment at - line 2, near "" +true";" - had compilation errors. ($down = 'false'); ((open(FH, $log) || $down) = 'true');
B::Deparse

Replies are listed 'Best First'.
Re: Re: open failure code
by Grygonos (Chaplain) on Nov 27, 2003 at 00:09 UTC

    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.


    Grygonos
      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.


        Dave


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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-19 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found