It might look a bit weird at first, but the map call works on a single listing that doesn't have duplication. I've also used the $ref->() style of calling which doesn't use an ampersand, but is functionally the same as &$ref().# Create a HASH which stores a mapping between function names # and the associated function references (\&). Add any other # functions to the quoted-word listing my %commands = map { $_ => \&$_ } qw[ set add mul ]; # ... while (<STDIN>) { my ($command, $param) = split(" ", $_); # Check that the function exists before calling it, could have a # bad $command being passed. Perhaps add a warning in an # else block? if ($command{$command}}) { $register = $command{$command}->($register, $param); } }
In reply to Re: Dynamically calling different functions?
by tadman
in thread Dynamically calling different functions?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |