For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > October 2004 > hash of hashes









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 hash of hashes
kimimila

2004-10-04, 5:46 am

Hi.
I have a file with a word and it's part-of-speech on each line.
I have so far put all words in one array and the part-of-speech in another so that one word's index corresponds with the part of speech.

But what I really want to do is to check which part-of-speech one word has ( it can have more than one) and then count how many times it has the different part-of-speech.

So I was thinking about using a hash of hashes where the parent hash has words as keys and hashes as value. The child hashes should have part-of-speech as keys and the number of these as values.

Like this example:

# %wordPos = (
# cat => {
# noun => 30,
# },
# race => {
# noun => 6,
# verb => 2,
# },
# jump => {
# noun => 3,
# verb => 7,
# },
# );


I don't know if there is a better way to do it. But I still don't know how to build this hash of hashes with the input I get.

/Maria
Sponsored Links







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

Copyright 2008 codecomments.com