On Wed, Sep 10, 2014 at 4:18 AM, Rob Dixon <rob.di...@gmx.com> wrote: > 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. >
Hm, I believe you're in error IIRC. What happens is perl's internal array structure for @x is marked inaccessible when the sub exits.This enables the struct to be more quickly resurrected on subsequent calls. Scope is preserved without doing extra work on re-entry. Note the IIRC. Corrections welcome. -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/