Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Not getting desire output by using switch statement in Perl

by Lennotoecom (Pilgrim)
on Jan 06, 2014 at 19:27 UTC ( #1069574=note: print w/replies, xml ) Need Help??


in reply to Not getting desire output by using switch statement in Perl

as an option
%a = map {$_ => ++$i} a..z; chomp($_ = <STDIN>); exists $a{$_} ? print "$a{$_}\n" : print "Everything else\n";

Replies are listed 'Best First'.
Re^2: Not getting desire output by using switch statement in Perl
by choroba (Chancellor) on Jan 06, 2014 at 22:16 UTC
    You can use the ternanry operator to save you typing print twice:
    print exists $a{$_} ? $a{$_} : 'Everything else', "\n";

    This is how I use the ?:.

    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      awesome, thank you

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1069574]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2016-12-03 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (60 votes). Check out past polls.