The stupid question is the question not asked | |
PerlMonks |
Re^8: Why is my code assigning the last-retrieved value to all elements in my hash?by punch_card_don (Curate) |
on Jul 09, 2008 at 22:32 UTC ( [id://696580]=note: print w/replies, xml ) | Need Help?? |
Thanks a heap for taking time to deal with this completely and in detail.
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. Time flies like an arrow. Fruit flies like a banana.
In Section
Seekers of Perl Wisdom
|
|