in reply to Re: Sorting an array based on hash values
in thread Sorting an array based on hash values
Of course, this runs through @to_be_ordered twice, which is inefficient. So you might use two temporary arrays:my @sorted = ((sort {$order{$a} <=> $order{$b}} grep {exists $order{$_}} @to_be_ordered), grep {not exists $order{$_}} @to_be_ordered);
my (@exists, @not_exists); push @{exists $order{$_} ? \@exists : \@not_exists }, $_ for @to_be_or +dered; my @sorted = ((sort {$order{$a} <=> $order{$b}} @exists), @not_exists) +;
-- Mike
--
just,my${.02}
|
|---|