Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Question about ternary condition

by SimonClinch (Deacon)
on Jun 28, 2005 at 09:42 UTC ( #470543=note: print w/replies, xml ) Need Help??


in reply to Question about ternary condition

The first example uses assignment before the ? operator so that the parts of the RHS of the assignment will be executed predictably according to the condition to the left of the '?'.

The second example does not do any assigning before the ?. It's true that perl will execute an 'or' or 'and' in such a non-assignment context, but (IMHO) that feature cannot be assumed for all operators and apparently not '?'.

Hope this helps.

-S

Update: Precedence (offered later) is a tempting explanation but I think it is merely executing both assignments in the order left to right because without an assignment to drive the ?, the parser is forced to execute the lot and then go nowhere with the ? because it has no documented reason to

- but I do agree with using brackets to control the precedence or in this case, wake it up!

One world, one people

Replies are listed 'Best First'.
Re^2: Question about ternary condition
by monarch (Priest) on Jun 28, 2005 at 11:15 UTC
    Interestingly, I've had a debate with one PerlMonk about the prudence of programming safely using parenthesis or other such practices when unsure of the exact nature of the language. He then attacked me personally and pointed out how his team of crack coding buddies would not tolerate such wasteful use of text at his company, and would proceed to point out the nuances of Perl and demand that code would be written to suit.

    I for one always applaud a programmer for erring on the safe side, regardless of what such cowboys have to say, or what disclaimers they may preface their opinions with.

      I agree with you - I've had a similar problem this year when a competing company, nervous of its previously inconsistent perl coding style set about attacking mine as a kind of defence. I was accused of unnecessarily escaping things like '_' in regexps - 'What's this \_ doing here when _ will do...?' I was asked in an aggressive manner in front of a senior manager.

      One world, one people

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://470543]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2018-06-19 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (114 votes). Check out past polls.

    Notices?