Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: ?: = Obfuscation?

by philcrow (Priest)
on Dec 01, 2006 at 16:48 UTC ( [id://587233]=note: print w/replies, xml ) Need Help??


in reply to ?: = Obfuscation?

If the test is really short, you can make tables with either if/else or ?:
if ( $score >= 90 ) { $grade = 'A'; } elsif ( $score >= 80 ) { $grade = 'B'; } #... else { $grade = 'F'; }
$grade = ( $score >= 90 ) ? 'A' : ( $score >= 80 ) ? 'B' : ( $score >= 70 ) ? 'C' : ( $score >= 60 ) ? 'D' : 'F';
Both of these degrade badly as the line length grows.

But, even if you like ifs (which I do mostly), tables are better than:

if ( $score >= 90 ) { $grade = 'A'; } elsif ( $score >= 80 ) { $grade = 'B'; } #...

Phil

Log In?
Username:
Password:

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

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

    No recent polls found