rongrw has asked for the wisdom of the Perl Monks concerning the following question:
Is it possible to call a class method whose name is stored in a scalar variable? For example, consider the following code.
Cheers, Ron.package Class_A; sub Meth_U { ... } sub Meth_V { ... } sub Meth_W { ... } sub Dump_SV { my $self = shift; foreach my $a qw( U V W ) { my $method = "Meth_" . $a; # Call the method whose name is kept in a variable. $self->$method->(); # DOES NOT WORK } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Class method names in a scalar variable
by LanX (Saint) on Dec 23, 2013 at 15:19 UTC | |
|
Re: Class method names in a scalar variable
by tobyink (Canon) on Dec 23, 2013 at 15:28 UTC |