Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Trying to remove duplicate rows using hashes

by kyle (Abbot)
on Oct 21, 2008 at 15:52 UTC ( [id://718520]=note: print w/replies, xml ) Need Help??


in reply to Trying to remove duplicate rows using hashes

When you output, you use the value of $k2 as a hash reference, but the second time through the inner loop, its value has been replaced by the key that each returned on the first time through. You need something more like this:

while ( my ($k1, $href) = each %hash ) { while ( my ($k2, $k3) = each %{ $href } ) { } }

Incidentally, you use English without the important -no_match_vars option, and you use warnings as well as giving the -w, which is a bit redundant.

Also, your sample output is in the order that the lines were received, but you won't get your output in that order if you're using each and hashes for storage. There are ways of coping with that, but I can't tell if that's one of your requirements or not.

Replies are listed 'Best First'.
Re^2: Trying to remove duplicate rows using hashes
by Angharad (Pilgrim) on Oct 21, 2008 at 15:55 UTC
    Thanks for all your help so far. Much appreciated.

    As regards to the print out - you mean I have to use some kind of sort function if I want it looking like my example?

      Yes, you could sort them before you output them, or you can sort them separately in another process. The UNIX sort command is very effective for tabular data such as yours.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-23 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found