in reply to Why Does the Hash Seem Empty?

My guess is that you're adding empty key/value pairs to the hash. Show us the result of your extra print statements (if there's not too much).

What does trim() do? Could it be responsible for creating empty entries in your hash?

Some other comments about your code:

update: keys is unnecessary, as demonstrated by dave_the_m. I was thrown by the OP's use of $count, which doesn't count.