http://qs321.pair.com?node_id=472870

kiat has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I'm puzzled by the following code:

use strict; my $some_word = 'race'; my @letters = split //, $some_word; my (@array1, @array2); for (1..@letters) { my @new = @letters; push (@array1, \@new); push (@array2, \@letters); my $myshift = shift @letters; push(@letters, $myshift); } print "array1 contains:\n"; foreach my $aref (@array1) { print "@$aref\n"; } print "\n\n"; print "array2 contains:\n"; foreach my $aref (@array2) { print "@$aref\n"; }
The output is as follows:

array1 contains: r a c e a c e r c e r a e r a c array2 contains: r a c e r a c e r a c e r a c e
I was expecting array2 to contain the same elements as array1 but that's not the case. Can someone explain why?

Thanks in anticipation.