in reply to A C-like brain in a Perl-like world

Boy, that's a lot of work. Try this:

my %uniq; @merged = grep { ++$uniq{$_} == 1 } (@array1, @array2);

(darren)

Replies are listed 'Best First'.
Re: Re: A C-like brain in a Perl-like world
by jerrygarciuh (Curate) on Sep 28, 2001 at 00:58 UTC
    What is the incrementation doing there? Is it moving
    through the keys of %uniq to see if $_ is a match?
    TIA,
    jg
      The key is that $uniq{$_} does not exist the first time a specific $_ is seen. Because it is preincremented, its value becomes 1. Then it is tested against == 1, and well, that is true. The next time that $_ is seen, $uniq{$_} already has a value of 1 or higher, so after the preincrement it becomes 2 or higher, then fails the == 1 test and is therefor dropped by grep. Thus, only the first appearance of a certain $_ makes it into the final list.