in reply to while going through perldsc tutorial...
In the line marked #WRONG, the reference is always taken to @array which is only allocated once in the program (probably implicitly). Therefore, on each iteration, @array gets new values, and its location gets stored and all those references refer to the last set of values. To fix it, declare @array on each iteration:
Then, new memory is allocated each time and the references are to those different memory areas.my @array = somefunc($i);
Phil
The Gantry Web Framework Book is now available.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: while going through perldsc tutorial...
by convenientstore (Pilgrim) on Oct 16, 2007 at 21:27 UTC |
In Section
Seekers of Perl Wisdom