Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Multiple if-else statements using C-style ternary operator

by spazm (Monk)
on Jul 11, 2011 at 22:46 UTC ( [id://913795]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $message = $status == 2 ? 'HIGH' 
                : $status == 1 ? 'MODERATE'
                : 'LOW'
    
    print $message
    
  2. or download this
    my %status_message = { 2 => 'HIGH', 1=>'MODERATE', 0=>'LOW' };
    my $message = $status_message{ $status } || 'LOW';
    
  3. or download this
    my @status_messages = qw( LOW MODERAGE HIGH );
    my $message = $status_messages[$status] || 'LOW';
    

Log In?
Username:
Password:

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

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

    No recent polls found