http://qs321.pair.com?node_id=189007


in reply to Unique array w/o repeated elements and still keep the original order!

foreach my $instance (@lines2) { print OUTF $instance unless $hsh{$instance}++; }
Tiago
Update: replaced 'if' with 'unless'. thanks robobunny
  • Comment on Re: Unique array w/o repeated elements and still keep the original order!
  • Download Code

Replies are listed 'Best First'.
Re: Re: Unique array w/o repeated elements and still keep the original order!
by robobunny (Friar) on Aug 09, 2002 at 19:50 UTC
    i'm assuming it was just a typo, but i think you meant:
    foreach my $instance (@lines2) { print OUTF $instance unless $hsh{$instance}++; }
    as written, it will only print the duplicates.