Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Statement Modifiers, Whaa?

by hopes (Friar)
on May 09, 2002 at 05:50 UTC ( [id://165260]=note: print w/replies, xml ) Need Help??


in reply to Statement Modifiers, Whaa?

It's because of precedence.

not have more precedence than the others you're using. You are making this:
return "Get Lost!" if (not $nice) or return "Hi"
while what you want is this:
return "Get Lost!" if not ($nice or return "Hi")



Hopes
$_=$,=q,\,@4O,,s,^$,$\,,s,s,^,b9,s, $_^=q,$\^-]!,,print

Replies are listed 'Best First'.
Compile the source, Luke (Re: Statement Modifiers, Whaa?)
by cmilfo (Hermit) on May 10, 2002 at 03:53 UTC
    This is where the Perl compiler becomes your best friend. If you run perl -MO=Deparse,-p [your script name here], the presedence Perl sees will be printed out. See below for your code example from above, which I stored in hello.pl.
    [cmilfo@cmilfo monks]$ perl -MO=Deparse,-p hello.pl ($nice = 0); sub hello1 { (($nice or return('Hi')) or return('Get Lost!')); } sub hello2 { (((!$nice) || return('Hi')) and return('Get Lost!')); } print(hello1(), hello2()); hello.pl syntax OK
    It basically puts in all the () and {} that we may not see.

    Cheers!
    Casey

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://165260]
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: (4)
As of 2024-04-25 05:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found