For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > April 2006 > Sorting a Hash to pattern









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Sorting a Hash to pattern
gnome

2006-04-01, 4:09 am

Hi Guys,

I am pretty new to perl and don't know if this should be in the newbie forum but here goes?

I am trying to sort the keys / values of one hash "A" in the same order as Hash "B" the common link between the two Hashes is that the data in the keys of both hashes is the same though at present not in the same order. I would then like to print out the key value pairs of hash "B" in the same order as Hash "A"

Data Input

hash "A"

key............................value (score)
the cat sat on the mat.........60
the dog chased the cat.........40
the mouse ate the cat..........36

hash "B"
key............................value (line position in text)
the mouse ate the cat..........19
the cat sat on the mat..........2
the dog chased the cat..........8

Desired output
key............................value (score)
the cat sat on the mat.........2
the dog chased the cat.........8
the mouse ate the cat..........19


Thanks in advance for any ideas

gnome
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com