noelgolding has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; #this works fine my $methodWithoutParam = \&myMethod; &$methodWithoutParam; # however, the next line actually executes the method. Not desired my $methodWithParam = \&myMethod('My Param'); # and the attempt to call the method generates an error. # Not a CODE reference at ... &$methodWithParam; sub myMethod { 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"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how can I store a reference to a method/function along with the parameters?
by Skeeve (Parson) on Aug 11, 2011 at 19:34 UTC | |
by JavaFan (Canon) on Aug 11, 2011 at 21:11 UTC | |
by noelgolding (Initiate) on Aug 12, 2011 at 13:03 UTC | |
|
Re: how can I store a reference to a method/function along with the parameters?
by johngg (Canon) on Aug 11, 2011 at 20:55 UTC | |
|
Re: how can I store a reference to a method/function along with the parameters?
by cdarke (Prior) on Aug 12, 2011 at 08:38 UTC | |
|
Re: how can I store a reference to a method/function along with the parameters?
by Arunbear (Prior) on Aug 12, 2011 at 10:26 UTC |