Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Object get method as variable name

by blue_cowdawg (Monsignor)
on Jan 09, 2013 at 19:39 UTC ( #1012553=note: print w/ replies, xml ) Need Help??


in reply to Object get method as variable name

Consider the following:

#!/usr/bin/perl -w use strict; my $s = new speak(); foreach my $critter(qw/ cat dog spider /){ $s->$critter(); } exit(0); package speak; sub new { bless {},"speak"; } sub cat { print "meow!\n"; } sub dog { print "woof!\n"; } sub spider { print "arf!\n"; } 1;
which may give you some enlightenment that you seek.

When run it yields:

$ ./doit.pl meow! woof! arf!
Hope this is of some help.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg


Comment on Re: Object get method as variable name
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2015-07-06 16:47 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 (77 votes), past polls