Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2016-02-10 03:49 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (331 votes), past polls