Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Conditional Operator Confusion

by davorg (Chancellor)
on Nov 29, 2006 at 12:14 UTC ( [id://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"; }
--
<http://dave.org.uk>

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

Replies are listed 'Best First'.
Re^2: Conditional Operator Confusion
by Melly (Chaplain) 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, pm@tomandlu.co.uk
      ??
      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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-19 20:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found