braveghost has asked for the wisdom of the Perl Monks concerning the following question:
It's just an example to show the problem.my $l = new z; $l->{xxx4} = 'wrong way'; my $str = 'xxx'; my $str1 = "4"; my $str2 = "param1"; eval ("print \$l->$str$str1(\$str2)"); package z; sub new { my $class = shift; my $self = {}; return bless $self, $class; }; sub xxx4 { my $self = shift; my $param = shift; return "were requested xxx4: $param \n"; };
I want make same actions without using eval.eval ("print \$l->$str$str1(\$str2)");
so for my case it will be something like$method = $fast ? "findfirst" : "findbest"; $fred->$method(@args); # call by name
the question is: can it be done at single string?my $method = $str.$str1; print $l->$method($str2);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: method invocation syntax at perl
by lodin (Hermit) on Jan 03, 2008 at 10:26 UTC | |
by braveghost (Acolyte) on Jan 03, 2008 at 13:21 UTC | |
by Fletch (Bishop) on Jan 03, 2008 at 14:34 UTC | |
by braveghost (Acolyte) on Jan 03, 2008 at 14:50 UTC | |
|
Re: method invocation syntax at perl
by jbert (Priest) on Jan 03, 2008 at 11:53 UTC | |
by braveghost (Acolyte) on Jan 03, 2008 at 13:34 UTC | |
|
Re: method invocation syntax at perl
by ForgotPasswordAgain (Vicar) on Jan 03, 2008 at 10:00 UTC |