On 09/09/2014 02:20, Ken Peng wrote:
The second option creates the same array and populates it, but then
copies it to another anonymous array, deletes the first array, and
returns a reference to the copy.
Since this is a shadow copy, I don't think the first array will be
deleted completely. Isn't it?
The second option is this
sub myfunc {
my @x=(1,2,3);
return [@x];
}
And yes, the array @x is created, populated, and deleted completely
every time the subroutine is called.
In the first option
sub myfunc {
my @x=(1,2,3);
return \@x;
}
the array isn't deleted as long as the reference returned by the
subroutine is held somewhere, but as all references to it are gone it
too will be deleted.
Rob
---
This email is free from viruses and malware because avast! Antivirus protection
is active.
http://www.avast.com
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/