in reply to Re^2: remove duplicates with hash and grep
in thread remove duplicates with hash and grep
Your code redefines %seen and @array each time you read a line from your file. You get duplicates because your hash is always empty when you test it for a value.
The following will produce a list of the unique values from IN:
my (%seen,@unique); while (<IN>) { chomp; $seen{$1}++ if ($_ =~ /^.+\.([A-Za-z0-9-_]+\.[A-Za-z]{2,})$/); } @unique = keys %seen; printf "%s, ",$_ for @unique; print "\n";
Updated for readability and coherence and typos (is it Monday already?)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: remove duplicates with hash and grep
by Smith (Initiate) on Dec 23, 2014 at 15:19 UTC |