I was meandering through the Class::Delegation docs when I happened upon this:
a little-known feature of the -> operator is that if a hash access is performed on a string, that string is taken as a symbolic reference to a package hash variable in the current package
Now of course we won't ask where in the Perl docs this is documented, because it probably isn't. But let us give an example of it
use strict; package Mr::Rogers; %Mr::Rogers = ( instrument => 'violin', clothing => 'cardigan', deameanor => 'mild', age => sub { rand 20 + rand 60 } , habitat => 'US-unknown'); map { __PACKAGE__->{cookies_eaten}++ if (rand 10 > 5) } (1..5) ; warn __PACKAGE__->{cookies_eaten};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Bad Symref! Naughty!
by dragonchild (Archbishop) on Nov 03, 2001 at 02:29 UTC | |
|
Re: self-referent hash for your packages
by blakem (Monsignor) on Nov 03, 2001 at 02:57 UTC | |
by tye (Sage) on Nov 03, 2001 at 04:03 UTC | |
by princepawn (Parson) on Nov 03, 2001 at 04:49 UTC | |
by tye (Sage) on Nov 03, 2001 at 05:10 UTC |