in reply to Re: Storing arrays as object variables
in thread Storing arrays as object variables

I always like to give a code example. This is a simple demonstration of how data sticks arround even though the original @array is out of scope. You rarely have to worry about losing data when it goes out of scope. You really have to watch for memory leaks when you create circular references. Read perlreftut and perlref for more info.
use strict; my $arrayref; { #create a closure for @array my @array = qw(zero one two three); $arrayref = \@array; } # @array is out of scope but @array's data still there print $arrayref->[1],"\n"; # prints "one" $arrayref->[4] = $arrayref; # circular reference. $arrayref = 1; # memory leak ! # @array's memory is never freed # until program ends!

--

flounder