Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996915]
help
Chatterbox?
[erix]: oh, 41M views -- everyone has seen it already then :)
[erix]: Alvin Lee dead too -- we're stuck with Karl, I'm afraid :)
[erix]: ok, one to remember Alvin Lee (Ten Years After - Help Me)
stevieb has a significant craving to hear "My guitar gently weeps"...
[Corion]: stonecolddevin: I think Jack White is highly regarded, but ...
[Corion]: ... I'm not really knowledgeable about good guitar players
[stonecolddevin]: I've been on a Stevie Ray Vaughan kick lately: https://www. youtube.com/watch? v=wVjdMLAMbM0
[stonecolddevin]: Corion I haven't heard much of his work to be honest.
[erix]: here is a nice cover, stevieb

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2017-06-22 21:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (531 votes). Check out past polls.