[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":
http://search.cpan.org/~xmath/Data-Swap-0.02/lib/Data/Swap.pm
Regards,
----------------------------------
Offer Kaye
More information about the Perl
mailing list