On 3/25/06, Practical Perl <[EMAIL PROTECTED]> wrote: > Hi,list, > > When a subroutine return a value,for example,this value is a pointer to an > array,which is get defined in this subroutine.When out of the > subroutine,some a statement call this subroutine and receive the return > value to a variable named as $aaa.Is $aaa a duplicate of the pointer in that > subroutine?Thanks. > > sub test { > @abc = qw/aa bb cc dd/; > return [EMAIL PROTECTED]; > } > > my $aaa = test( ); > >
No. $aaa is not a duplicate of @abc, it's a refernce to @abc. If you change $aaa, @abc will change, too, and vice versa. Consider a slightly more complicated example (not that this code, like yours, will fail under 'use strict'): sub mytest { push @abc, qw/aa bb cc dd/; return [EMAIL PROTECTED]; } $aaa = mytest(); # $aaa has [aa,bb,cc,dd] mytest(); # $aaa has [aa,bb,cc,dd,aa,bb,cc,dd] Reinitializing @abc with my each time will create a local variable for each instance of the subroutine, but you'll still have a refernce, not a copy. If you want to make a duplicate of an array, just use '='. @aray2 = @array1. HTH, -- jay -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org values of β will give rise to dom!