[Israel.pm] swap arrays

Offer Kaye oferk at oren.co.il
Tue Feb 17 03:13:54 PST 2004

> Actually, there is.  And it works the same way as scalar substitution.
> The answer is in a seldom used feature of perl called 'typeglobs'. But
> code first:
> perl -e '@a=(1,2);@b=(3,4);(*a,*b)=(*b,*a);print @a, at b,"\n"'
> Output: 3412

Nice, since it even works when the arrays are not the same size. Hoever, if
I declare @a and @b with "my", this trick doesn't work anymore:
perl -e 'my @a=(1,2);my @b=(3,4);(*a,*b)=(*b,*a);print @a, at b,"\n"'
Output: 1234

Any idea why not?

Offer Kaye

More information about the Perl mailing list