In Perl, you can call a function by reference (or name) as follows:
my $functionName = 'someFunction';
&$functionName();
sub someFunction { print "Hello World!"; }
What I'm trying to do is use a value from Hash, for example:
my %hash = (
functionName => 'someFunction',
);
&$hash{functionName}();
sub someFunction { print "Hello World!"; }
And the error I get is that the global character "$ hash" requires an explicit package name.
My question is: is there a proper way to do this without using an intermediate variable?
Any help on this would be greatly appreciated!
source
share