# Comes right out of the Switch.pm synopsis 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" } } # # Instead, write the below. Yeah, it's a little sloppy, # but I just want to show that it can be done. # for $i ($val) { $i == 1 && do { print "number 1"; last }; $i eq "a" && do { print "string a"; last }; grep { $i == $_ } @{[1..10,42]} && do { print "number in list"; last }; grep { $i == $_ } @array && do { print "number in list"; last }; $i =~ /\w+/ && do { print "pattern"; last }; $i =~ qr/\w+/ && do { print "pattern"; last }; exists $hash{$i}&& do { print "entry in hash"; last }; exists $hash->{$i} && do { print "entry in hash"; last }; sub($i) && do { print "arg to subroutine"; last }; print "previous case not true"; }