Usually the lack of distinction between function and method is a problem in Perl, but here it means that you can use can() on a package name even if it's not a class and get back a subroutine reference even if it's not a method.
package My::Awesome::Package; use 5.010; sub foo { ... } sub bar { ... } sub baz { ... } package main; for my $func (qw( foo bar baz quux )) { next unless my $func_ref = My::Awesome::Package->can( $func ); say "Found code for '$func': ", $func->(); }
In reply to Re^2: How to call sub defined in a variable?
by chromatic
in thread How to call sub defined in a variable?
by jh-
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |