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.

Replies are listed 'Best First'.
Re^2: List Compare
by Anonymous Monk on Oct 21, 2005 at 14:35 UTC

    Hello blazar, Read the question properly, OP has asked:

    I can compare this manually with for loops, but i want to know, is there any module to perform this task.

    Another think, Read the update part:

    If @b = (b, c, d), it is also wrong, because here the order is correct with @a, but a is not there in @b, so it is error, ie it should check from the beginning of @a

    Eventhen your reply is WRONG