In Perl 5.10.1:
#!/usr/bin/perl
my @a = (1, 2, 3);
my $b = \@a;
print join('', @{$b}) . "\n";
@a = (6, 7, 8);
print join('', @{$b}) . "\n";
This prints 123 then 678. However, I'd like to get 123 both times (i.e. reassigning the value of @a will not change the array that $b references). How can I do this?
$aor$bin general Perl code.$aand$bare globals used by thesortfunction and they will be overwritten ifsortgets called by your code or by any module it uses. (Yes, I realize that declaring them lexically (withmy) sidesteps that because you're not using the global version then, but it's still asking for trouble to use$aor$b.)