in reply to Sorting an array by another array
(update fixed if statement, and the sort line)my $VERY_LARGE_NUMBER = 999999999; sub index_of { my ( $item, @array ) = @_; my $i = 0; while ( $i < @array ) { return $i if ( $array[$i] eq $item ); $i++; } return $VERY_LARGE_NUMBER; } # Use the Schwatz, luke! @sorted = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ index_of( $_, @order ), $_ ] } @to_be_sorted;
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important
|
|---|