in reply to Calling a subroutine from a scalar
You take a reference to the function and store it in a scalar, then dereference the scalar.use strict; sub func1 { print "Here\n"; } my $var = \&func1; $var->();
If you want to use the name of the function, the best thing to do is a dispatch table.
my %dispatch = ( func1 => \&func1, func2 => \&func2, ); my $var = 'func1'; $dispatch{$var}->();
This way, you know which function names will be used and how they will be used.
|
|---|