Switch case in perl
first download Switch then use
use Switch;
$var =1;
switch($var){
case 1 { print "1\n";}
case 2 { print "2\n";}
case 3 { print "3\n";}
case 4 { print "4\n";}
case 5 { print "5\n";}
else { print "6\n"; }
}
or
use Switch;
$var = 10;
@array = (10, 20, 30);
%hash = ('key1' => 10, 'key2' => 20);
switch($var){
case 10 { print "number 100\n" }
case "a" { print "string a" }
case [1..10,42] { print "number in list" }
case (\@array) { print "number in list" }
case (\%hash) { print "entry in hash" }
else { print "previous case not true" }
Comments
Post a Comment