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


in reply to Re^2: How to map function name to coderef?
in thread How to map function name to coderef?

You can use can to return a coderef:

use strict; use warnings; my $doFoo = main->can ('foo'); print $doFoo ? $doFoo->() : "Can't foo\n"; sub foo { return 1; }

Prints:

1
True laziness is hard work

Replies are listed 'Best First'.
Re^4: How to map function name to coderef?
by ikegami (Patriarch) on Jan 07, 2012 at 00:37 UTC
    can searches the inheritance tree. It should be used for methods, not functions.

      And yet can works, and as there is no @main::ISA, and you shouldn't pollute UNIVERSAL,  main->can( $foo ) is perfectly legit

        How do you know there's no @ISA?