in reply to Re^2: Modifying a parameter to a recursive function
in thread Modifying a parameter to a recursive function
I don't think that is really the OP's problem. What you suggest can be checked trivially by:
use strict; use warnings; my @array = (1 .. 8); print "Before: @array\n"; nastyModifyParamsSub (@array); print "After: @array\n"; sub nastyModifyParamsSub { for my $element (@_) { ++$element; } }
Prints:
Before: 1 2 3 4 5 6 7 8 After: 2 3 4 5 6 7 8 9
Which shows that modifying the parameters is possible and that there is nothing magical about requiring $_ to do it. The following though shows one way that OP's code could be going awry:
use strict; use warnings; my @array = (1 .. 8); print "Before: @array\n"; nastyModifyParamsSub (@array); print "After: @array\n"; sub nastyModifyParamsSub { for (@_) { ++$_; clobberDefVar (); } } sub clobberDefVar { $_ = 0; }
Prints:
Before: 1 2 3 4 5 6 7 8 After: 0 0 0 0 0 0 0 0
The bottom line though to that the OP's description is an fuzzy unclear thing and there is too much code and no data at all.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Modifying a parameter to a recursive function
by ikegami (Patriarch) on Apr 08, 2009 at 21:53 UTC |