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<robert.ci...@gmail.com> 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: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/