UPDATE - here is the updated code that I used along with some other subssub Return_Middle { my @list = @_; return @list if ( scalar(@list) == 2 or scalar(@list) == 1 ); my @sorted = sort { $a <=> $b || $a cmp $b } @list; my @middle = drill_down(@sorted); return @middle; sub drill_down { my @list = @_; return @list if ( scalar(@list) == 2 ); return @list if ( scalar(@list) == 1 ); splice @list, -1, 1; splice @list, 0, 1; drill_down(@list); } }
my $SORTED = \&Do_Sort; sub Return_First { return $SORTED->(@_)->[0]; } sub Return_Last { return $SORTED->(@_)->[$#{ $SORTED }]; } sub Return_Middle { return $SORTED->(@_) if @_ < 3; splice @_, -1, 1; splice @_, 0, 1; Return_Middle(@_); } sub Do_Sort { sort { $a <=> $b || $a cmp $b } @_; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: function that returns the middle of an array
by blazar (Canon) on Jan 10, 2006 at 14:26 UTC | |
|
Re: function that returns the middle of an array
by Roy Johnson (Monsignor) on Jan 10, 2006 at 15:57 UTC | |
by ambrus (Abbot) on Jan 10, 2006 at 17:30 UTC | |
|
Re: function that returns the middle of an array
by ambrus (Abbot) on Jan 10, 2006 at 17:36 UTC |