Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Perl ternary operator style

by TomDLux (Vicar)
on May 30, 2011 at 15:35 UTC ( [id://907331]=note: print w/replies, xml ) Need Help??


in reply to Perl ternary operator style

I agree with BrowserUK and others about appropriate use of || or //.

More generally, I would say ternary operator is great when you have simple values to compare. If the terms become complicated, you want something else, maybe an actual IF block. It's not just a matter of making the code work correctly. The code needs to be decipherable for the sucker who has to read it six months from now to implement some change requirement.

As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Replies are listed 'Best First'.
Re^2: Perl ternary operator style
by David Clarke (Initiate) on Jun 01, 2011 at 14:03 UTC
    Many thanks, TomDLux (and others) for pointing out that my use of ?: in this kind of situation is blindingly (to the subsequence reader) over-complex. I think this is a case where copy-paste-reuse has become embedded in some of my work, and ternary is the norm. I'll go an re-evaluate what is actually needed. David Clarke.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-03-28 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found