Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: List Compare

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


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://502006]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-25 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found