in reply to Using IF and OR, I'm sure there is a better way
For more flexibility, try a hash:# Setup my @ok; ++$ok[$_] for 1, 2, 3; # Sample usage if ($ok[$variable]) { ... }
These are just one step away from a dispatch table:# Setup my %fruit; ++$fruit{$_} for qw( apple banana orange ); # Sample usage if ($fruit{$object}) { ... }
# Setup my %dispatch = ( colour => \&area_fill, scale => \&scale_image, warp => \&warp_image, ); # Sample usage if ($handler = $dispatch{$command}) { $handler->(); } else { die("Invalid command $command\n"); }
Update: Keep in mind that 1, 2, 3 can be written as 1..3
|
|---|