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; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hash function
by Anonymous Monk on Oct 07, 2006 at 17:23 UTC |