Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: in search of a more elegant if then else

by FunkyMonk (Chancellor)
on Feb 19, 2010 at 11:10 UTC ( [id://824135]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $n = 3;
    
    ...
          :           'ETOOBIG';
    
    print "$n : $s\n"; # 3 : three
    
  2. or download this
    my %h = ( 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four' );
    
     $s = $h{$n} // 'ETOOBIG'; # needs perl 5.10
    #$s = $h{$n} || 'ETOOBIG'; # works for any perl
    print "$n : $s\n"
    

Log In?
Username:
Password:

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

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

    No recent polls found