in reply to sort an array according to another array

Do benchmarking on your method, and any other method you come across. Here's my idea, but I'm sure there's others.

If @L's elements are unique, and @S is truly a subset of @L, then one way would be:

$i = 0; %L = map { $_ => $i++ } @L; @Ss = sort { $L{$a} <=> $L{$b} } @S;

It requires more intermediary storage, but perhaps a simpler operation.

Test results:

@L = qw(one two three four five six seven eight); @S = qw(eight one five three); @Ss = qw(one three five eight);

--
[ e d @ h a l l e y . c c ]