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