in reply to Sorting an array by another array

This is a bit of code I hacked up once upon a time that did this:
sub SuggestionSort { my ($toSort, $Suggestion) = @_; my (%sugg, $i, @sorted); foreach (@{$Suggestion}) { $sugg{$_} = $i++ }; foreach (@{$toSort}) { if (defined $sugg{$_}) { $sorted[$sugg{$_}] = $_ } else { $sorted[$i++] = $_ } } grep defined, @sorted; }
You would call it this way:
use strict; my @order = qw(whale elephant dog cat); my @sortme = qw(foo bar baz cat dog elephant bird); print join(", ", &SuggestionSort(\@sortme, \@order)),"\n";
Good Day,
  Dean