Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: if and else

by fullermd (Priest)
on Aug 18, 2009 at 05:10 UTC ( [id://789342]=note: print w/replies, xml ) Need Help??


in reply to if and else

Neither of those snippets is doing what you think it is. Look at what B::Deparse tells you.

% perl -MO=Deparse -e 'print "TRUE" if ( 0 ) or die "FALSE"' print 'TRUE' if die 'FALSE'; % perl -MO=Deparse -e 'print "TRUE" if ( 0 ) or print "FALSE"' print 'TRUE' if print 'FALSE';

Basically, Statement Modifiers are the last thing on a line, so your if ( 0 ) or die "FALSE" actually means if( (0) or die "FALSE"). And the return value of the die (or print) is what determines whether your initial print actually runs. Since print is returning something true, and die doesn't return, you end up with the results you saw.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-03-29 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found