Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^3: Invoking a method whose name is computed

by GrandFather (Sage)
on Oct 02, 2012 at 20:39 UTC ( #996915=note: print w/replies, xml ) Need Help??

in reply to Re^2: Invoking a method whose name is computed
in thread Invoking a method whose name is computed

An advantage of the "wasted variable" (I prefer to think it is an "intelligently used variable") is that you can perform a little validation:

my $object = bless {hi => 'hello'}; for my $suffix ('x', 'y') { my $method = $object->can("prefix_$suffix"); $object->$method() if $method; } sub prefix_x { my ($self) = @_; print "$self->{hi} world\n"; }

Update: elaborate code to better show intent.

True laziness is hard work

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996915]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2016-10-23 22:11 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (302 votes). Check out past polls.