On Tue, Jun 26, 2001 at 04:46:24PM -0400, Bradford Ritchie wrote:
> ...but I really need to print everything after the 8th element. If the
> ...array were named, I could do something like this:
>
> @arr = split(/:/);
> print @arr[1,6,8..$#arr]);
Your asked question was answered well by Stephen Nelson (except it should be
"use an array", not "name the array", as you are currently not using an
array, but I pedantically digress), so I won't elaborate.
> ... and this would include everything after the 8th array element. I know
> ... that -1 should start from the end of the array, but specifying
> ... [1,6,8..-1] doesn't work.
However, this I will elaborate on. If you think about it you will be able
to tell why a slice of [8..-1] doesn't work. The ".." operator is not just
used in array slicing, it's a more general range operator. What sense does
8 .. -1 make outside of the context of a slice? Count from 8 to.. what,
-1? That's not what you want from the slice, you want 8 to the end.
There have been several discussions on p5p, and I believe even some perl6
lists, regarding special-casing the ".." operator within a slice, but they
usually devolve to disagreement on what it should do outside of a slice.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--