|
|
| laziness, impatience, and hubris | |
| PerlMonks |
Re: counting elements using a hashby Marshall (Prior) |
| on Sep 23, 2012 at 02:02 UTC ( #995152=note: print w/ replies, xml ) | Need Help?? |
|
The first task is to get the "number" that you wish to track from the input lines. The second step is simply to count using a hash table. It is not necessary to test for exists(). Perl will create a new key if the key doesn't exist.
Try again and show some just a couple of lines of example input and your revised code. There is no need to iterate over all 101 possibilities for the number on each line. Process each line once, get the number, make a decision and it is "over with" - don't loop 100 times for each input line.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||