Your individual actions need to have matching call signatures (same number of arguments, same order) for this to work. If your subs already exist and don't have exactly the same signatures, you can either write wrapper subs or use anonymous subs in the actions table. Note that if you want to call methods, you'd simply put the method names in the action table and then use this to call the selected method:my %actions = ( 1 => \&error_entry, 2 => \&warning_entry, ); my $action_sub = $actions{$value_to_check} || \&default_action; $action_sub->($args_for_this);
This makes it totally trivial to add or change the number of alternatives, and is a hash lookup, so no matter how many alternatives you have, the time to find and run any given one is exactly the same (handwaving hash collisions here).$object->$method($args_for_this);
In reply to Re^5: Why is my script not printing anything?and how to add a switch case in perl
by pemungkah
in thread Why is my script not printing anything?and how to add a switch case in perl
by iphone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |