Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Conditional Operator Confusion

by davorg (Chancellor)
on Nov 29, 2006 at 12:14 UTC ( #586666=note: print w/ replies, xml ) Need Help??

in reply to Conditional Operator Confusion

Looks like it's operator precendence. This works as you expected.

for(1..10){ $_>5 ? ($x='foo') : ($x='bar'); print "$_:$x\n"; }

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Comment on Re: Conditional Operator Confusion
Download Code
Re^2: Conditional Operator Confusion
by Melly (Hermit) on Nov 29, 2006 at 12:39 UTC

    Well, pfft - that's no good for golf... although I'm still confused - how does precedence work in this context?

    Tom Melly,
      C:\>perl -MO=Deparse,-p for(1..10){ $_>5 ? $x='foo' : $x='bar'; print "$_:$x\n"; } ^Z foreach $_ (1 .. 10) { ((($_ > 5) ? ($x = 'foo') : $x) = 'bar'); print("${_}:$x\n"); } - syntax OK

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2015-03-27 00:36 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (597 votes), past polls