in reply to Strange hash array behavior
As used, { } creates an (anonymous) hash, assigns the contents of the curlies to that hash, and returns a reference to that hash.
In the first snippet, you create a new hash in every pass of the loop. You assign a reference to the newly created hash to $r->{cat}. Thus, every record references a different hash.
In the second snippet, you create one anonymous hash outside the loop. You assign a reference to that hash to $r->{cat}. Thus, you have multiple records referencing that one hash.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Strange hash array behavior
by Rodster001 (Pilgrim) on Jan 29, 2009 at 03:25 UTC | |
by Util (Priest) on Jan 29, 2009 at 05:02 UTC | |
by Rodster001 (Pilgrim) on Jan 29, 2009 at 05:19 UTC | |
by ikegami (Patriarch) on Jan 29, 2009 at 15:26 UTC | |
by ig (Vicar) on Jan 29, 2009 at 05:53 UTC | |
by Rodster001 (Pilgrim) on Jan 29, 2009 at 06:14 UTC | |
| |
by Util (Priest) on Jan 29, 2009 at 06:27 UTC |