in reply to Re: Invoking a method whose name is computed
in thread Invoking a method whose name is computed
You invoke Foo::bar_baz as function, not as method. For a method call, the object / class name implicitly added by perl is missing, so you have to add it manually:
Class->can("prefix_$name")->(Class,'first argument'); $object->can("prefix_$name")->($object,'first argument');
Hardly DRY. I prefer "wasting" a variable for composed method names:
my $method="prefix_$name"; Class->$method('first argument'); $object->$method('first argument');
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Invoking a method whose name is computed
by GrandFather (Saint) on Oct 02, 2012 at 20:39 UTC |