my $func_name = ( $someCondition ? 'foo' : 'bar' ); my $func_ref = __PACKAGE__->can($func_name); # or other pac +kage $func_ref->($arg1, $arg2);
I'm sure there is a similar method like can() in Python too.
> What is the name of the idiom
When talking to non-Perlers I'd use the general term "introspection"
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
->can is also strict and more stable, since you can easily catch missing subs.
It won't work with AUTOLOAD though
In reply to Re: Function name in a variable, can't recall the concept (introspection with ->can )
by LanX
in thread Function name in a variable, can't recall the concept
by mpersico
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |