Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Operator precedence

by muba (Priest)
on Jan 12, 2013 at 23:15 UTC ( #1013070=note: print w/replies, xml ) Need Help??


in reply to Re: Operator precedence
in thread Operator precedence

So simple... and still I somehow overlooked it.

Thanks a lot, BrowserUk!

Replies are listed 'Best First'.
Re^3: Operator precedence
by BrowserUk (Pope) on Jan 12, 2013 at 23:35 UTC

    Not that it helps particularly with this particular expression, but the output from B::Deparse is often enlightening.

    I love the fact that perl turns that into a low precedence boolean operator used for flow control and a postfix if. P::C must get righteously apoplectic :)

    C:\test>perl -MO=Deparse,p use 5.010; sub apple { say "apple" } sub banana { say "banana" } sub cherry { say "cherry" } apple && (banana || cherry) ^Z sub BEGIN { require 5.01; } sub apple { no feature; use feature ':5.10'; say 'apple'; } sub banana { no feature; use feature ':5.10'; say 'banana'; } sub cherry { no feature; use feature ':5.10'; say 'cherry'; } no feature; use feature ':5.10'; banana or cherry if apple ; - syntax OK

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      ehm, there's a typo ...

      ...if you want to activate extra options like parens to emphasize the precedence you need to prepend a minus, i.e. -p

      $ perl -MO=Deparse,-p use 5.010; sub apple { say "apple" } sub banana { say "banana" } sub cherry { say "cherry" } apple && (banana || cherry) __END__ ... yadda ...yadda ... (apple() and (banana() || cherry()));

      UPDATE

      well it's still not too clear about left-to-right.

      I know there is somewhere an option to combine the optree with readable code, not sure if in B::Deparse or B::Concise or B::Terse

      UPDATE Terse and Concise have the option -src but it doesn't help that much, cause it's line based.

      Cheers Rolf

      I do feel I am a seasoned perl programmer myself, but in this example, that B::Deparse only confuses me. Who would ever write

      banana or cherry if apple ;

      to make things clear? I would NEVER use that construct. The give construct by the OP causes no mental parsing problems whatsoever.


      Enjoy, Have FUN! H.Merijn
        to make things clear? I would NEVER use that construct.

        I wasn't advocating it, I was just amused by it :)

        That said, I think the terms confuse things because they mean nothing, How about:

        open( FH, '<', $ARGV[ 2 ] ) or die( "$! : $ARGV[ 2 ]" ) if $ARGV[ 2 ];

        Or:

        eval $code or die $@ if $code;

        Doesn't seem so uncommon once you substitute realistic terms.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013070]
help
Chatterbox?
[Discipulus]: good morning monks! town holiday here.. but super busy
Discipulus time is not comarable with money.. when you have a roof and something to eat
[Corion]: Hi Discipulus! Busy making the town better? ;)
[Discipulus]: the house I hope.. now i'm going on the roof putting some protection for the sun. afternoon 150 km for a water polo training (son, obviously..)
[Corion]: Discipulus: Ah - lazy roof-sitting ;)
[Corion]: (well, after you've put on the sun protection ;) )
[Corion]: But I should be moving into town as well, do some chores and get my hair cut...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2017-06-29 08:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (655 votes). Check out past polls.