I have a Perl scalar ($mystr) that holds a string. I want to use the
scalar to form a hash reference to a method after the Perl code is compiled.
For example, when I know the method name before compile time, I can say:
use strict;
%Hashref=( Entry1=>{meth1=>\&method1, do=>'something'},);
and then later execute method1 by using:
$Hashref{Entry1}{meth1}($a,$b,$c);
How can I assign the hash method reference using the contents of the scalar
$mystr, in such a way, that I can use the same syntax to execute the method
name stored in $mystr.
NOTE: I have already used the following, but would prefer to use method
references for both:
$Hashref{Entry1}{meth1}=$mystr;
...
if(ref($Hashref{Entry1}{meth1}) eq 'CODE') {
$retval =$Hashref{Entry1}{meth1}($a,$b,$c);
} else {
no strict 'refs';
$retval=&{$Hashref{Entry1}{meth1}}($a,$b,$c);
use strict 'refs';
}
Thanks in advance.