Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Sub ref from string without eval

by Anonymous Monk
on Apr 02, 2012 at 20:19 UTC ( #963108=note: print w/ replies, xml ) Need Help??


in reply to Sub ref from string without eval

If you know which package you expect your subroutine to be in you might also be able to use the functionality of UNIVERSAL::can

use strict; use warnings; sub Foo { warn 'foo'} my $x = 'Foo'; my $sub_ref = main->can($x); $sub_ref->();


Comment on Re: Sub ref from string without eval
Download Code
Replies are listed 'Best First'.
Re^2: Sub ref from string without eval
by Rhandom (Curate) on Apr 03, 2012 at 13:38 UTC
    Which is generalized even better as:

    my $sub_ref = __PACKAGE__->can($x);

    my @a=qw(random brilliant braindead); print $a[rand(@a)];

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (14)
As of 2015-07-31 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (282 votes), past polls