in reply to Grabbing slices
The following seems to do what you want. Not sure if this is the most efficient approach though.
use strict; use warnings; use Data::Dumper; my (@array, $iIndex, $thisValue, $lastValue, @out); @array = qw(x x y z z z); @out = (0); $lastValue = $array[0]; for ($iIndex = 0; $iIndex <= $#array; $iIndex++) { $thisValue = $array[$iIndex]; if ($thisValue ne $lastValue) { push @out, ($iIndex - 1, $iIndex); $lastValue = $thisValue; } } push @out, $#array; print Dumper(\@out);
Regards,
Dom.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Grabbing slices
by dbush (Deacon) on May 03, 2003 at 19:20 UTC | |
by Util (Priest) on May 03, 2003 at 21:59 UTC |