How about this? You find the middle of the array, which will either be an integer or a half-value. Return the slice indexed from the integer portion of the midpoint through the integer portion of the midpoint + .5. If the midpoint is a half-value, those will be different (so you return the two values that straddle the middle); otherwise, they will be the same, and you return just one value.
sub Return_Middle {
my $midpt = ($#_/2);
@_[int($midpt) .. int($midpt + .5)];
}
Update:
The text description in the OP suggests that the array is already sorted, so I didn't see the point of sorting it again. But my code could be a drop-in for
drilldown instead of
Return_Middle, or a sort step could be added to it:
sub Return_Middle {
my $midpt = ($#_/2);
(sort {$a <=> $b or $a cmp $b} @_)[int($midpt) .. int($midpt + .5)];
}
Caution: Contents may have been coded under pressure.