I'm not sure how your input file is generated/populated, but it might be worth thinking about doing more than chomp in your foreach loop - such as dealing with leading/trailing whitespaces and capitalization. Consider the the following quoted strings and if they all should be counted under the same key in your hash:
- " apple"
- "apple "
- "APPLE"
- "Apple"
- " APPle "
If you trust that the input file won't have such variations, then it might not cause you issues if you decide to not add some code to handle those situations.
Another thing to consider is that using %dict and $dict might lead to some confusion for yourself later. The same could happen with using $wd and $wds.
Just sharing the thoughts that popped into my mind when looking over your code. Not saying that any of the above is necessarily "wrong", but those are the types of things that have gotten me into trouble with my code.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.