dsb has asked for the wisdom of the Perl Monks concerning the following question:
I've got some behavior I think is a bit odd, and I'm guessing it's just b/c of the way perl handles things internally, but I'm curious as to how/why this is happening.
I have a function being called by a code ref stored in a hash of code refs. The function is passed on the command line, and then by a series of conditions, is called from a class method of package Util.pm like so:
Where $fname is the name of a function parse() in a seperate package, Parse.pm.sub dispatch { my ($self, $fname) = @_; &{$dispatchTable{$fname}}; ## note, no arguments }
In Parse.pm, parse()'s first few lines are
$isCombined is a variable meant to give the user the option to string a series of functions together into a collective check rather than run each individually. In this case, with parse() seeming called with no arguments, I expected $isCombined to be undefined.sub parseAutorep { my $isCombined = shift;
However, it's getting set with the Util.pm object that contains the dispatch() method that is calling parse().
it almost seems like, behind the scenes, the full call looks like:
or something like that.Util::dispatchTable->Parse::parse();
UPDATE: It actually looks like parse() is getting the same argument list that was passed to the function that called it, dispatch(), if that sheds any light for anyone.
Anyone have any insight? At this point, the simple answer is to just shift the object out of the way...no biggie. But I'm really just curious about what's happening here.
dsb
This @ISA my( $cool ) %SIG
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: strange code (de)referencing behavior
by choroba (Cardinal) on Feb 10, 2012 at 15:37 UTC | |
by ikegami (Patriarch) on Feb 10, 2012 at 19:26 UTC | |
Re: strange code (de)referencing behavior
by kennethk (Abbot) on Feb 10, 2012 at 15:54 UTC | |
Re: strange code (de)referencing behavior
by Anonymous Monk on Feb 10, 2012 at 15:52 UTC |