http://www.perlmonks.org?node_id=1069574


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 (Cardinal) 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