Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How to call sub defined in a variable?

by snoopy (Curate)
on Jan 26, 2009 at 01:29 UTC ( [id://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;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-25 22:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found