in reply to how to call a sub via variable in library
COMMANDWith the updated post above, it becomes clear that BrowserUk's suggestion is correct. The code:Orginal non-OO: &{\&{$testname}}($system); updated as OO: $self->{&{\&{$testname}}}->($system); #system is hashr +ef
translates to $testname->($system); with a hack to get around the ban on Symbolic references. Essentially, you have a scalar storing the name of that routine, which then calls that function with the argument $system. To change that to a method call on $self, you would want&{\&{$testname}}($system);
as documented in Method Names as Strings in perlobj.$self->$testname($system);
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|