Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: calling subroutines from variables

by Tanktalus (Canon)
on Aug 21, 2008 at 17:16 UTC ( [id://705884]=note: print w/replies, xml ) Need Help??


in reply to calling subroutines from variables

You could use sub references instead:

@listofsubs = (\&sub1, \&sub2, \&sub3); foreach $sub (@listofsubs) { $sub->(); }
Or you might be doing this on objects:
foreach $sub (@listofsubs) { $self->$sub() }
Or you could just try to find them... if they're in the current package, this might work (untested):
foreach $sub (@listofsubs) { if (not ref $sub) { $sub = __PACKAGE__->can($sub); } $sub->(); }
(by checking if it's a ref, you could comingle names and code-refs: @listofsubs = ('sub1', \&sub2, sub { do_stuff() }); - the object example can handle this, too, only better.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 17:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found