Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: List Compare

by blazar (Canon)
on Oct 21, 2005 at 14:24 UTC ( #502006=note: print w/replies, xml ) Need Help??

in reply to List Compare

#!/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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://502006]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2018-07-22 12:46 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (454 votes). Check out past polls.