in reply to Grabbing slices

#! perl -slw use strict; my @array = qw[ x x y z z z ]; my @idxs = 0; $array[$_-1] ne $array[$_] and push @idxs, $_-1, $_ for 1 .. $#array; push @idxs, $#array; print "@idxs";

Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.

Replies are listed 'Best First'.
Re: Re: Grabbing slices
by jgallagher (Pilgrim) on May 03, 2003 at 19:37 UTC
    Let me see if I can expand this correctly...
    my @idxs = (0); my $i; foreach $i (1 .. $#array) { if ($array[$i - 1] ne $array[$i]) { push @idxs, $i - 1, $i; } } push @idxs, $#array; print "@idxs";