http://www.perlmonks.org?node_id=963108


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->();

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)];