Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^4: Perl Parsing Based on Supplied Precedence

by protist (Monk)
on Nov 07, 2012 at 11:49 UTC ( #1002661=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Perl Parsing Based on Supplied Precedence
in thread Perl Parsing Based on Supplied Precedence

"&&" and "and" have differing precedences. "and" is lower precedence than "&&". The same goes for "||" and "or"; "or" has lower precedence than "||". "and" actually has lower precedence than "||", as I will demonstrate.

code with "&&":

perl -e 'if(0&& 0||1){print"hello\n"}'

output:

hello

code with "and":

perl -e 'if(0and 0||1){print"hello\n"}'

(outputs nothing)


Comment on Re^4: Perl Parsing Based on Supplied Precedence
Select or Download Code
Re^5: Perl Parsing Based on Supplied Precedence
by wirito (Acolyte) on Nov 07, 2012 at 12:01 UTC
    Yes, you are right. I meant to say:
    '&&' and 'and' operator has higher precedence than '||' and 'or' respectively
    English is not my first language as you can notice :)

      Ah. After I saw your precedences in your example below, I was confused because you seemed to understand haha. I will note here that I was not attempting to mirror Perl precedences in my example precedence, only create a precedence for testing purposes. Your precedence list is more Perl-like.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2015-07-06 08:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls