Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How to call sub defined in a variable?

by snoopy (Deacon)
on Jan 26, 2009 at 01:29 UTC ( #738856=note: print w/ replies, xml ) Need Help??


in reply to How to call sub defined in a variable?

Also consider putting the subroutines in their own name-space:

#!/usr/bin/perl use strict; use warnings; package MySubs; sub test { print "something"; } sub another_test { print "something else"; } sub third_test { print "another unimaginative statement"; } 1; package main; my @ary = qw( test another_test third_test ); my $sub_i_want_to_call = $ary[rand(@ary)]; my $subref = MySubs->can($sub_i_want_to_call); &$subref() if $subref;


Comment on Re: How to call sub defined in a variable?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2014-09-02 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (29 votes), past polls