Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Quick question. Assume the following variable values:
my $meth = "prefix_foo"; my $x = "foo";
Perl allows me to do this:
Some::Class->$meth;
but not this:
Some::Class->"prefix_$x";
My workaround at the moment is:
Some::Class->${\("prefix_$x")};
Is there a more straightforward version? Besides the more obvious two-statement version, that is.
my $tmp = "prefix_$x"; Some::Class->"prefix_$tmp";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Invoking a method whose name is computed
by tobyink (Canon) on Oct 01, 2012 at 23:43 UTC | |
|
Re: Invoking a method whose name is computed
by AnomalousMonk (Archbishop) on Oct 02, 2012 at 02:10 UTC | |
by afoken (Chancellor) on Oct 02, 2012 at 05:43 UTC | |
by GrandFather (Saint) on Oct 02, 2012 at 20:39 UTC | |
by tobyink (Canon) on Oct 02, 2012 at 16:30 UTC | |
|
Re: Invoking a method whose name is computed
by runrig (Abbot) on Oct 01, 2012 at 23:38 UTC | |
|
Re: Invoking a method whose name is computed
by Anonymous Monk on Oct 01, 2012 at 23:33 UTC |