Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: if and else

by fullermd (Priest)
on Aug 18, 2009 at 05:10 UTC ( #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
Node Status?
node history
Node Type: note [id://789342]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2020-12-06 01:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (65 votes). Check out past polls.

    Notices?