atemerev has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
I'd like to call some named method on some Perl object via its normal direct method call syntax. Like this:
my $doomsday_weapon = Weapon::Doomsday->new; my $method = 'destroy_the_world_with'; my @args = qw(WMD, PHP, NSA); eval("\$doomsday_weapon->$method(" . join(', ', @args) .")");
Is there a way to do this somewhat more elegantly and without the unsafe eval()?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calling a method by name without eval()
by FunkyMonk (Bishop) on Mar 23, 2008 at 17:24 UTC | |
by atemerev (Beadle) on Mar 23, 2008 at 17:36 UTC | |
|
Re: Calling a method by name without eval()
by whereiskurt (Friar) on Mar 23, 2008 at 17:44 UTC | |
by chromatic (Archbishop) on Mar 23, 2008 at 21:13 UTC | |
|
Re: Calling a method by name without eval()
by perrin (Chancellor) on Mar 23, 2008 at 18:27 UTC | |
|
Re: Calling a method by name without eval()
by ikegami (Patriarch) on Mar 23, 2008 at 23:11 UTC |