in reply to Getting range from N..end with list slice

Just a note: take care with using grep { defined } that way, for it might have odd side effects:

$ perl -wE '@x = qw"a b c d e f g h"; say 0+@x; say join ":", grep { d +efined } @x[4 .. 99]; say 0+@x;' 8 e:f:g:h 100 $

Replies are listed 'Best First'.
Re^2: Getting range from N..end with list slice
by ikegami (Patriarch) on Nov 27, 2010 at 21:38 UTC

    It's very hard to twist what the OP has into something that's a problem, so I guess you're just providing trivia. In that case, let me add that any lvalue context will suffice.

    >perl -E"@a[4..99] = (); say 0+@a;" 100 >perl -E"for (@a[4..99]) {} say 0+@a;" 100 >perl -E"sub {}->(@a[4..99]); say 0+@a;" 100 >perl -E"grep 1, @a[4..99]; say 0+@a;" 100