Nevermind, I knew I was overlooking something simple: use @ symbol.
$ perl -le '@a=(1,2,3,4) ; @a[0,1...@a[1,0] ; print join("\t", @a) ; '
2 1 3 4
Regards,
- Robert
On Fri, Jul 17, 2009 at 2:03 PM, Robert Citek<[email protected]> wrote:
> Is there an easier way to swap two values in an array?
>
> This works:
>
> $ perl -le '@a=(1,2,3,4) ; ($a[0],$a[1])=($a[1],$a[0]) ; print
> join("\t", @a) ; '
> 2 1 3 4
>
> This doesn't:
>
> $ perl -le '@a=(1,2,3,4) ; $a[0,1]=$a[1,0] ; print join("\t", @a) ; '
> 1 1 3 4
>
> Regards,
> - Robert
>
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/