Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: how can I store a reference to a method/function along with the parameters?

by Arunbear (Parson)
on Aug 12, 2011 at 10:26 UTC ( #920010=note: print w/replies, xml ) Need Help??


in reply to how can I store a reference to a method/function along with the parameters?

Store them separately? (And for calling a method, you don't really need a reference)
use strict; sub myMethod { my $self = shift; my ($param) = @_; if ($param) { print "Woohoo, you have successfully passed in a parameter ($p +aram).\n"; } else { print "You have not attempted to pass in a parameter.\n"; } } my ($method, @params) = ('myMethod', 'foo'); my $object = bless {}; $object->$method(@params);
output:
:! perl -w meth.pl Woohoo, you have successfully passed in a parameter (foo).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://920010]
help
Chatterbox?
[Eily]: yes we're pretty prawn to making puns around here
Eily went to the wiktionary to check that the pronunciations of prawn and prone are actually similar. Turns out prawn can be an alternative form of porn...
[Discipulus]: well i'm still at the end of the food chain..
[Discipulus]: so a new life as krill in prague will be good

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2017-06-29 12:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (662 votes). Check out past polls.