If all you need is a count of the number of iterations, and the keys are unique, you can use something as simple as:
$ perl -E 'my %x = (a=>1, b=>2, c=>3); say "Count: ", 0+keys(%x)'
Count: 3
If the situation is more complex than that
— non-unique keys; lines skipped for some reason; and so on —
you'll need to provide more information or I'm only guessing (and I don't really want to waste time doing that).
You should show some sample input: keep it short but still realistic with example exception cases.
Then show the expected output from that input.
If duplicate keys are encountered, should they be skipped or should their value overwrite the previous value.
Other reasons that lines might be skipped are: they're blank, are comments, don't match /^\S+\s+\S+$/, or something else.
What else is special that I should know about?
When I saw your OP code, I thought the first (non-MCE) loop, and the two counters, were just for testing.
Clearly, that was a poor guess; please help me out here.
|