A
Andrew Fleet
Hi,
I'm looking at returning a reference to an array I create within a
subroutine.
I could do this...
sub foo {
my @theArray;
<snip>
return \@theArray;
}
This works however I'm concerned I'm returning a reference to stack data. I
heard if I used 'local' rather than 'my' the array will always exist (it's
global), but using 'my' I'm creating a temporary stack based
array that will then be cleaned up when the subroutine returns, hence my
reference will be invalid.
So...my or local?
Thanks
Andy
I'm looking at returning a reference to an array I create within a
subroutine.
I could do this...
sub foo {
my @theArray;
<snip>
return \@theArray;
}
This works however I'm concerned I'm returning a reference to stack data. I
heard if I used 'local' rather than 'my' the array will always exist (it's
global), but using 'my' I'm creating a temporary stack based
array that will then be cleaned up when the subroutine returns, hence my
reference will be invalid.
So...my or local?
Thanks
Andy