cgoolsby has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
This question is more of a interesting concern.
I have some modularized code. In this code, I pass an array reference to a function which returns a different array as a reference.
i.e.:
Cheerfully,
C
P.S. this is my first post on here. If I am violating any rules, I apologize in advance. Also, if you see a simple way I can improve my conventions for coding, I am largely self-taught and happy to learn and improve!
For reference to module function looks like:use ModuleName qw(moduleFunction); @arrayPassedIn = qw(some values here); #there are 9 values, to be specific. $return = moduleFunction(\@arrayPassedIn); @arrayToPrint = @$return;
So here is the kicker. When I print @arrayToPrint, I get the 6 values that I desire, and then the last 3 values of the array I passed into my function. Is this as intended? Am I doing something wrong? It doesn't effect my code, because I just discard these values, but I am curious what is going on.sub moduleFunction{ $input = shift; @arrayToBeManipulated = @$input; #manipulations occur here producing a new array with 6 values; @newArray = qw(6 unique values); return \@newArray; }
Cheerfully,
C
P.S. this is my first post on here. If I am violating any rules, I apologize in advance. Also, if you see a simple way I can improve my conventions for coding, I am largely self-taught and happy to learn and improve!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Leaking Function Return
by haukex (Archbishop) on Oct 06, 2017 at 15:15 UTC | |
Re: Leaking Function Return
by Laurent_R (Canon) on Oct 06, 2017 at 15:22 UTC | |
by cgoolsby (Novice) on Oct 06, 2017 at 15:53 UTC | |
by haukex (Archbishop) on Oct 06, 2017 at 16:30 UTC | |
Re: Leaking Function Return
by 1nickt (Canon) on Oct 06, 2017 at 15:11 UTC |
Back to
Seekers of Perl Wisdom