Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: how to call a sub via variable in library

by kennethk (Abbot)
on Nov 17, 2014 at 22:17 UTC ( [id://1107494]=note: print w/replies, xml ) Need Help??


in reply to how to call a sub via variable in library

COMMAND
Orginal non-OO: &{\&{$testname}}($system); updated as OO: $self->{&{\&{$testname}}}->($system); #system is hashr +ef
With the updated post above, it becomes clear that BrowserUk's suggestion is correct. The code:
&{\&{$testname}}($system);
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
$self->$testname($system);
as documented in Method Names as Strings in perlobj.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1107494]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-25 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found