From: Robert Citek Date: 2007-12-20T08:58:34+09:00 Subject: slicing in ruby Is there a way to slice an array like in perl? For example, what's the ruby equivalent to doing this: $ echo $(seq 1 10) | tee /dev/stderr | perl -lane 'print join(" -- ", @F[1,2,3,8,2,2]) ' 1 2 3 4 5 6 7 8 9 10 2 -- 3 -- 4 -- 9 -- 3 -- 3 I can get this to work: $ echo $(seq 1 10) | tee /dev/stderr | ruby -lane 'print $F.join(" -- ") ' 1 2 3 4 5 6 7 8 9 10 1 -- 2 -- 3 -- 4 -- 5 -- 6 -- 7 -- 8 -- 9 -- 10 and this: $ echo $(seq 1 10) | tee /dev/stderr | ruby -lane 'print $F[1,2].join(" -- ") ' 1 2 3 4 5 6 7 8 9 10 2 -- 3 but not this: $ echo $(seq 1 10) | tee /dev/stderr | ruby -lane 'print $F[1,2,3,8,2,2].join(" -- ") ' 1 2 3 4 5 6 7 8 9 10 -e:1:in `[]': wrong number of arguments (6 for 2) (ArgumentError) from -e:1 There's probably some method I need to invoke, but which one? Regards, - Robert