in reply to Function name in a variable, can't recall the concept
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Function name in a variable, can't recall the concept (introspection with ->can )
by ikegami (Patriarch) on Apr 15, 2019 at 01:00 UTC | |
by LanX (Saint) on Apr 15, 2019 at 11:07 UTC | |
by ikegami (Patriarch) on Apr 16, 2019 at 19:21 UTC | |
by LanX (Saint) on Apr 16, 2019 at 21:30 UTC | |
by AnomalousMonk (Archbishop) on Apr 16, 2019 at 22:22 UTC | |
| |
by ikegami (Patriarch) on Apr 19, 2019 at 08:53 UTC | |
|