in reply to Re^7: Why is my code assigning the last-retrieved value to all elements in my hash?
in thread Why is my code assigning the last-retrieved value to all elements in my hash?
I do believe that the truly salient point is this:
There's one other misconception you seem to have that I'd like to clear up. You can't have a $b{foo}{bar} and have $b{foo} set to some unrelated value (such as 1). If there is a $b{foo}{bar}, then $b{foo} must somehow be a reference to a hash where you access ->{bar}. In your original code, that "reference" was "1", treated as a symbolic reference to %1. In the code I suggested, it's a hard reference to an anonymous hash that gets printed as 'HASH(0x8529f88)'.
This appears to be the real root of the problem. I started with a one-dimensional hash, then extended it to two dimensions. $booklist_1{$book_id} therefore becomes a reference to a hash and I can no longer use it the way I was trying to.
On this basis, I changed it to
and that works perfectly.while ($book_id = $sth->fetchrow_array()) { $booklist_1{$book_id}{'book_id'} = 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Why is my code assigning the last-retrieved value to all elements in my hash?
by kyle (Abbot) on Jul 10, 2008 at 03:30 UTC | |
by punch_card_don (Curate) on Jul 10, 2008 at 12:30 UTC |