1 2 3 4 5 6 7 8 9 10 11
use strict; use warnings; my $function = 'test'; call $function; <- ????? sub test { print "test"; }
1 2 3 4 5 6 7
my %table = ( test => \&test, foo => \&foo, ... ); my $var = "test"; $table{ $var }->($parameter);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
use strict; use warnings; my $fname = 'foo'; my $pkg = __PACKAGE__; if(my $code = $pkg->can($fname)){ $pkg->$code(1,2,3); } else{ die "No code for function '$fname'\n"; } sub foo{ print "this is sub foo in package 'main', args: @_\n"; }