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'; }
Both of these degrade badly as the line length grows.$grade = ( $score >= 90 ) ? 'A' : ( $score >= 80 ) ? 'B' : ( $score >= 70 ) ? 'C' : ( $score >= 60 ) ? 'D' : 'F';
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
|
---|
In Section
Meditations