Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: "Intelligent" array joining

by dragonchild (Archbishop)
on Feb 06, 2004 at 03:22 UTC ( [id://326978]=note: print w/replies, xml ) Need Help??


in reply to Re: "Intelligent" array joining
in thread "Intelligent" array joining

Doesn't work. Try the following test:
my @array1 = qw(dog cat rat mouse); my @array2 = qw(dog rat mouse bird); my @array3 = qw(cat rat fish mouse); my %seen; my @collection; foreach my $item ( @array1, @array2, @array3 ) { unless ( exists( $seen{$item} ) ) { push @collection, $item; $seen{$item}++; } } print "@collection\n"; @collection = (); %seen = (); foreach my $item ( @array2, @array1, @array3 ) { unless ( exists( $seen{$item} ) ) { push @collection, $item; $seen{$item}++; } } print "@collection\n"; __END__

Prints:

dog cat rat mouse bird fish dog rat mouse bird cat fish

Theoretically, it should always give the same order, no matter what order the initial arrays are in.

------
We are the carpenters and bricklayers of the Information Age.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Re: Re: "Intelligent" array joining
by QM (Parson) on Feb 06, 2004 at 23:36 UTC
    Theoretically, it should always give the same order, no matter what order the initial arrays are in.
    Ah, I missed that in the specification. I suppose if the OP could have stated the problem better, s/he might have known where to find it in the first place, no? ;)

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-18 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found