Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: "Intelligent" array joining

by valentin (Abbot)
on Feb 05, 2004 at 21:50 UTC ( #326900=note: print w/replies, xml ) Need Help??

in reply to "Intelligent" array joining

Let Tie::IxHash keep your order. I did not understand which order is prefered for your example, but put them in your order into the hash. That's what you get back.
my @array1 = (1, 3, 4, 6); my @array2 = (1, 2, 4, 6); my @array3 = (1, 2, 3, 5); tie my %seen, 'Tie::IxHash'; for (0..$#array1) { my @v = sort ( $array1[$_], $array2[$_], $array3[$_] ); @seen{ @v } = 1; } print join ' ', keys %seen;

Replies are listed 'Best First'.
Re: Re: "Intelligent" array joining
by ngomong (Sexton) on Feb 05, 2004 at 22:22 UTC
    Hmmm... this appears to be a step in the right direction, though I don't need that "sort" in there. You see, numerical order is of no importance... only the order in which it appears in the array. It's like this:

    my @array1 = (1, 3, 4, 6); my @array2 = (1, 2, 4, 6); my @array3 = (1, 2, 3, 5);
    So, the program looks as the first array, and notes its order. Then, it looks at the second array, and notices that "2" hasn't been seen before. It notes that it goes after "1" and before "4". At this point, the logical order could be either

    (1, 2, 3, 4, 6) or
    (1, 3, 2, 4, 6)

    It doesn't matter which it chooses. Then, it examines the third array and realizes that "2" comes before "3". Plus, the "5" is new, and comes after "3". So, now the order could be:

    (1, 2, 3, 4, 5, 6) or
    (1, 2, 3, 4, 6, 5)

    Does that make sense?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://326900]
[shmem]: LanX can get the logs from cbstream at any time from me.
shmem relocates to the pub over the street. Have a nice time.
[LanX]: well .. not so much interested in reading this article
[LanX]: my 2 cents: AngloZionistic sounds like an antisemtic theory, but to be critical of zionism doesn't mean to be anti-semitic
[shmem]: it hasn't been coined as a *mustread* without authority from the promoter
erix shoots an anti-bubble missile towards LanX
[LanX]: I don't have the time to go into depth of this blog though
[LanX]: anti-bubble missile?
[shmem]: LanX, it's not a matter of time, and you know that.
[shmem]: be precise.

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2018-03-19 21:35 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (246 votes). Check out past polls.