Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: finding unique items in an array, from a text file

by johngg (Canon)
on Jan 13, 2009 at 23:27 UTC ( [id://736109]=note: print w/replies, xml ) Need Help??


in reply to Re: finding unique items in an array, from a text file
in thread finding unique items in an array, from a text file

I think there might be a couple of problems with your code.

  • You join the output with \ns but you did not chomp the input so you will get extra blank lines.
  • Hash keys are unordered so the line order of the original file will be scrambled. This may or may not be an issue.

The grep solutions suggested might be better if line order is to be preserved. Something like (again, not tested).

... my %seen = (); print grep ! $seen{ $_ } ++, <$fh>; ...

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^3: finding unique items in an array, from a text file
by andye (Curate) on Jan 14, 2009 at 12:41 UTC
    All good points. ;)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://736109]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2024-04-25 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found