in reply to hash function

As the category/word combinations are being stored in the hash combined into each key:

# from your add_words() sub ... $words{"$category-$word"} += $words_in_file{$word};

You cannot make use of the main feature of hashes (O(1) lookup), and you will instead have to iterate the keys of the hash, break them into their components and the print the word if the category matches.

sub show_classification{ my ( $wantedCategory ) = @_; #for each word in the matching category, print the word for my $key ( keys %words ) { my( $category, $word ) = split '-', $key; print "$word\n" if $category eq $wantedCategory; } }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: hash function
by Anonymous Monk on Oct 07, 2006 at 17:23 UTC
    Thanks BrowserUK! I don't fully understand it, but I'll sit down with my perl book now and figure out what you've done. cheers!