Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Invoking a method whose name is computed

by GrandFather (Cardinal)
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


Comment on Re^3: Invoking a method whose name is computed
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2014-07-25 02:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls