Syntactic Confectionery Delight | |
PerlMonks |
Re^3: create hash names dynamicallyby cdarke (Prior) |
on Jun 11, 2007 at 13:57 UTC ( [id://620494]=note: print w/replies, xml ) | Need Help?? |
The others have explained it well (I had to nip out to get my car fixed - don't tell my boss). The push adds a new element to an array, I guess you know about that. The braces {} are called composers that create a hash and return a reference to it. In this case the hash is empty, but we could have placed a key=>value list(s) inside. So push is just putting a reference to the hash into the array. The hashes do not have a name, they are (as others have said) anonymous. Which is great, because it means we don't have to stretch our imagination to think up umpteen hash names. The memory for the hash will be freed up once the array itself is freed, or assigned to something else (there's a bit more to it, try searching for "Perl reference counting" if this concerns you).
In Section
Seekers of Perl Wisdom
|
|