in reply to Why is my code assigning the last-retrieved value to all elements in my hash?
I deleted your database code and substituted $sth->fetchrow() with (rand(),rand()). My output was ok, no repetition of the last element.