in reply to Merging Arrays without duplicates

simple merge @merge = (@A, @B)

for more tricks see perlfaq4 {Data Arrays}

upd: To merge without duplicates:

@A = (1,2,3,4,5,6); @B = (1,2,3,4,5,6,7,8,9); @seen{@A} = (); @merged = (@A, grep{!exists $seen{$_}} @B); print @merged;

Replies are listed 'Best First'.
Re^2: Merging Arrays without duplicates
by perl_krish (Initiate) on Aug 18, 2004 at 14:06 UTC
    yup jus got there (to faq4 i mean) ...... guess now i got to become a perl junkie :D
Re^2: Merging Arrays without duplicates
by perl_krish (Initiate) on Aug 18, 2004 at 14:31 UTC
    hey i am new to this ... could u explain real quick wat lines 3 and 4 do? Thanks Krish

      @seen{@A} = ();
      is the same as

      $seen{$A[0]}) = undef; $seen{$A[1]}) = undef; $seen{$A[2]}) = undef; $seen{$A[3]}) = undef; ...

      @merged = (@A, grep{!exists $seen{$_}} @B);
      is the same as

      @C = grep{!exists $seen{$_}} @B; @merged = (@A, @C);

      @C = grep{!exists $seen{$_}} @B;
      @C is assigned the contents of @B not seen in %seen. In other words,
      @C is assigned the contents of @B not seen in @A.

        Hey and what would $seen{$_} do ???
        $_ = each value of A and then compare it with each B ?
        AM i right?
        Thanks
        Krishna