http://www.perlmonks.org?node_id=502006


in reply to List Compare

IIUC:
#!/usr/bin/perl -l use strict; use warnings; { my @a=qw/a b c d e f/; my %order; for (0..$#a) { $order{ $a[$_] } = $_ + 1; } sub idx { $order{$_[0]} || 0 } sub order { sort { idx($a) <=> idx($b) } @_; } } $,=$"; print +(order qw/f d b/); __END__
(optimized for clarity rather than for performance)

Update: I hadn't "UC"... (see Re^2: List Compare). Still this code is not that bad after all. Maybe he could try to adapt it to his needs -- I just don't have time to do so now.