Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: ?: = Obfuscation?

by philcrow (Priest)
on Dec 01, 2006 at 16:48 UTC ( #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


Comment on Re: ?: = Obfuscation?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-09-19 04:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls