[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: [PATCH 5.005_63] Open-ended slices: (a..z)[23..]
Mark-Jason Dominus <mjd@plover.com> writes:
|| I didn't mention it on speculation. I mentioned it because I have
|| relied on it.
||
|| Simon sais the same thing, and I don't think it is as unlikely as
|| either of you seem to think.
||
|| Other times this has come up, I've noticed that there seem to be two
|| sorts of people involved in the debate. For some people, it is an
|| abnormal discontinuity that ($x..$y) yields the empty list when $y<$x.
|| For others, it seems perfectly normal.
||
|| The first group of people cannot imagine that anyone would ever
|| actually make use of such an abnormal discontinuity. The second group
|| finds it perfectly normal.
I also have code that computes end points and then uses them,
comfortable in the knowledge that a null list (where the
computed $x is greater than the computed $y) just quietly does
nothing.
# (binsearch returns index of first element that is >= the
# specified value)
$start_index = binsearch( $array, $start_value );
$past_end_index = binsearch( $array, $end_value+1 );
foreach( @{$array}[ $start_index .. $end_index-1 ] ) {
# ...
}
Often, these index positions are collected "in passing" during an
examination of the array done for another purpose.
$start_index = @$array;
$end_index = -1;
while( ... ) {
# ...
# interesting parts of $array are examined, current index is $index
$start_index = $index
if $index < $start_index && $array->[$index] >= $start_value;
$end_index = $index
if $index > $end_index && $array->[$index] <= $end_value;
# ...
}
foreach( @{$array}[ $start_index .. $end_index ] ) {
# ...
}
--
John Macdonald jmm@jmm.pickering.elegant.com
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]