Hello, I was looking for a select case or switch for PERL and it seems there is no built in command for this, I did a search and found two possibilities.
1. Use the Switch module
2. use a for command...like so
Which is best, what's the overhead of invoking the switch module compared to using a for?
what would you use?
regards,
1DMF.
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
1. Use the Switch module
Code:
use Switch;
switch ($val) {
case 1 { print "number 1" }
case "a" { print "string a" }
case [1..10,42] { print "number in list" }
case (@array) { print "number in list" }
case /\w+/ { print "pattern" }
case qr/\w+/ { print "pattern" }
case (%hash) { print "entry in hash" }
case (\%hash) { print "entry in hash" }
case (\&sub) { print "arg to subroutine" }
else { print "previous case not true" }
}
2. use a for command...like so
Code:
SWITCH: for ($where) {
/In Card Names/ && do { push @flags, '-e'; last; };
/Anywhere/ && do { push @flags, '-h'; last; };
/In Rulings/ && do { last; };
die "unknown value for form variable where: `$where'";
}
Which is best, what's the overhead of invoking the switch module compared to using a for?
what would you use?
regards,
1DMF.
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.