Some example code (untested.)..
my @array1 = ('Paula', 'Sherri', 'Cynthia', 'Ludovico'); my @gotback = names_a(); $gotback[0] = 'Jimmy'; # @array1 is still ('Paula', 'Sherri', 'Cynthia', 'Ludovico') my $gotback = name_aref(); $gotback->[0] = 'Jimmy'; # @array1 is now ('Jimmy', 'Sherri', 'Cynthia', 'Ludovico') my @gotback2 = @{ names_aref() }; # makes a copy $gotback2[0] = 'Back to Paula'; # @array1 is still ('Jimmy', 'Sherri', 'Cynthia', 'Ludovico') # because we made a copy by doing @{ names_aref() } sub names_a { # this really returns # 'Jimmy', 'Sherri', 'Cynthia','Ludovico' # and not @array1 # when received at the other end, it may be slapped # back togeter into an array, # but it will be a new list (a new array) return @array1; } sub names_aref { # this returns a reference, therefore both what this is # returning and the original @array1 both point to the # same space in the symbol table (place in memory). return \@array1; }
In reply to Re: Best way to return array or hash?
by leocharre
in thread Best way to return array or hash?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |