in reply to Array sort - kind of...
@array = sort { $a->[2] <=> $b->[2] } @array
But, you say you want to find the $i with the smallest z value. It's best to _not_ sort for that:
my $min_i = 0; foreach my $i (1..$#array) { $min_i = $i if $array[$i]->[2] < $array[$min_i]->[2]; }
(update: Oops. Forgot the ->[2].)
This should be signifigantly faster, especially when @array gets large...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Array sort - kind of...
by Anonymous Monk on Feb 04, 2002 at 02:07 UTC | |
by demerphq (Chancellor) on Feb 04, 2002 at 11:16 UTC | |
by petral (Curate) on Feb 04, 2002 at 20:47 UTC | |
by demerphq (Chancellor) on Feb 05, 2002 at 10:25 UTC | |
by wog (Curate) on Feb 04, 2002 at 02:13 UTC |
In Section
Seekers of Perl Wisdom