Perl: the Markov chain saw | |
PerlMonks |
Re: Anonymous Thingiesby hanenkamp (Pilgrim) |
on Oct 21, 2003 at 20:58 UTC ( [id://301065]=note: print w/replies, xml ) | Need Help?? |
Why would you want such a thing? Frequently. Since Perl flattens lists:
is equivalent to:
Anonymous hashes/arrays are essentially used prevent this from being done. What's the scope on an anonymous thingie? To quote the Camel Book: Anonymous: Used to describe a referent that is not directly accessible through a named variable. Such a referent must be indirectly accessible through at least one hard reference. When the last hard reference goes away, the anonymous referent is destroyed without pity. That is, it goes away immediately if it isn't assigned to be referenced by something. Will they ever die/get lost/get clobbered? Perl 5 uses reference counting for garbage collection. As soon as the reference count on the reference goes to zero, it will be "destroyed without pity." Therefore, the statement:
Get's canned immediately, while:
lasts until all three variables go out of scope or are assigned different values or, ultimately, when the interpreter exits if one of these is global or never goes out of scope and is never reassigned.
In Section
Seekers of Perl Wisdom
|
|