Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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


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 drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2015-07-29 05:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls