in reply to Re: 'my' Variable life cycle
in thread 'my' Variable life cycle
The following shows the memory being re-used.
sub func1 { my $x; print(\$x, "\n"); return \$x } sub func2 { my $x; print(\$x, "\n"); return } push @a, func1() for 1..5; print("\n"); func1() for 1..5; print("\n"); func2() for 1..5; print("\n");
SCALAR(0x226d1c) SCALAR(0x225ffc) SCALAR(0x226cb0) SCALAR(0x1830a6c) SCALAR(0x1830a84) SCALAR(0x1830a9c) SCALAR(0x1830ab4) SCALAR(0x1830a9c) SCALAR(0x1830ab4) SCALAR(0x1830a9c) SCALAR(0x1830910) SCALAR(0x1830910) SCALAR(0x1830910) SCALAR(0x1830910) SCALAR(0x1830910)
Note that the implementation of lexicals actually differs a lot from your description, but your post is an accurate description of how lexicals should be perceived to work.
|
|---|