Well, if you're OK with printing the colons in the last field, you could
simply say:

print ( ( split(/:/, $_, 9) )[1,6,8] );

Since that'll absorb all of the ending fields into the ninth (from zero, so
index 8) field. That would be the correct thing to do if the colons in the
ending field are not field delimiters, but just part of the text.
Other than that, you may need to bite the bullet and name the array.

> -----Original Message-----
> From: Bradford Ritchie [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, June 26, 2001 1:46 PM
> To: [EMAIL PROTECTED]
> Subject: array slice question
>
>
> Hi,
>
> I have an unnamed array which I created from splitting up a colon
> separated string:
>
>       $_ = "0th:1st:2nd:3rd:4th:5th:6th:7th:Some random text:
> might have :colons: or might not"
>       print ((split /:/)[1,6,8]);
>
> ...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]);
>
> ... 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.
>
> I didn't see anything in perldata about it so I'm hoping someone
> has a solution.
>
> Thanks.
> -- Brad
>
>

Reply via email to