Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Unique array w/o repeated elements and still keep the original order!

by tstock (Curate)
on Aug 09, 2002 at 15:10 UTC ( [id://189007]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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 15: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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://189007]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.