Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: "or die" versus "|| die"

by gellyfish (Monsignor)
on Jun 24, 2005 at 15:08 UTC ( [id://469732]=note: print w/replies, xml ) Need Help??


in reply to Re: "or die" versus "|| die"
in thread "or die" versus "|| die"

No they cannot be used interchangeably in all places, the word versions are specifically guaranteed to have lower precedence than the symbol versions (infact guaranteed to have the lowest precedence of any operators), you might care to try for instance:

open ONE, "somefilethatdoesnexist" or print "one: $!\n"; open TWO, "somefilethatdoesnexist" || print "two: $!\n";
As you can see the latter doesn't behave as expected as the '||' binds more tightly and ends up taking the value of the filename - infact the check is optimised away because this is essentially a no-op, as the output from B::Deparse shows:
print "one: $!\n" unless open ONE, 'somefilethatdoesnexist'; open TWO, 'somefilethatdoesnexist';

/J\

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-28 20:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found