Robert Citek wrote:
This doesn't:
$ perl -le '@a=(1,2,3,4) ; $a[0,1]=$a[1,0] ; print join("\t", @a) ; '
perl -Mstrict -Mwarnings -le '@a=(1,2,3,4) ; $a[0,1]=$a[1,0] ; print
join("\t", @a) ; '
Always use strict and warnings :)
--
Just my 0.0002 million dollars worth,
Shawn
Prog
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
Regar
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 wrote:
> Is there an easier way to swap two values in an array?
>