[Israel.pm] swap arrays

Offer Kaye oferk at oren.co.il
Mon Feb 16 08:28:29 PST 2004

> Hi,
> Is there an **elegant** way of swapping arrays in Perl ?
> I call "elegant", the way we swap scalars:
>  ($a,$b)=($b,$a);
> Yossi

If the arrays are the same size you could do:
(@b[0..$#a], at a) = (@a, at b);

Or you could try Michael's method (roll your own function), or use a CPAN
module like "Data::Swap":

Offer Kaye

More information about the Perl mailing list