in reply to Hash key counting

This doesn't work for me, the value of $key_num is always the same, why doesn't this work?

Are you sure that @discounts contains a 1? If not, you'd never be assigning a new key.

Show us a tiny, complete script that demonstrates this problem.