Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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]
[marto]: the boys uncle will take them for a couple of hours this afternoon :)
[marto]: only at work 3 days this week, then off to Copenhagen for a wedding
[marto]: back the following Monday, potentially gone 2-3 days the next week for work
[Corion]: Oh - "Cyber Monday" week is coming up... That's why weird stuff is already discounted now...
[Corion]: marto: Oh, cool, I hope you get to enjoy the trip and Copenhagen! I found it nice (but the mermaid is underwhelming)
[marto]: the kids and their mother are coming too, actually only 9 people at the wedding in total. Still, will be fun

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2017-11-19 11:41 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (280 votes). Check out past polls.