|
Posted by dummy on March 19, 2008, 9:50 pm
Please log in for more thread options
On Thu, 20 Mar 2008 01:19:10 +0000 (UTC), Ben Bullock
>On Wed, 19 Mar 2008 16:41:19 -0700, dummy wrote:
>
>> $ow = \@in;
>
>The two lines like this cause the problem. When a program uses "my @in"
>inside a loop, it creates a new @in each time it goes around the loop.
>Usually if you have
>
>my $something
>
>inside a loop, Perl destroys it at the end of the loop, but here you have
>taken a reference to it, so Perl keeps it.
>
>However, when you put "my @in" outside the loop, the above reference
>points to the same old @in each time, so \@in points to the same old
>thing each time, hence your problem.
>
>You can fix this by copying the whole @in array into another array:
>
> my @crud = @in;
> $ow = \@crud;
>
>But that may not be the optimal solution.
Thank you for the explanation. I was able to fix it by moving the 'my'
declaration inside the loop, where it belonged, but I couldn't figure
out why that fixed it. I am HAPPY to find that there is no bug in perl.
|