Today : What's a stash ?
In common english, a stash is a hidden place, used to secretly store
precious things. So what's a stash in Perl ? Well, it's more or less the same
thing : a hidden data structure, used to store precious things. It's also an
acronym for Symbol Table hASH : the internal hash where all your global
variables live. (This double meaning makes this word particularly
well-crafted.) Each package Foo defined into a perl program has its
own stash, %Foo:: (note the trailing double colon.) The keys of the
hash are the symbol names, and the values are the globs corresponding to those
values. Here's an example
$Foo::x = 42;
print "$_,$Foo::{$_},${$Foo::{$_}}\n" for keys %Foo::;
This small snippet outputs x,*Foo::x,42.
Note that stashes can live in other stashes, as demonstrated by the
following code
$Foo::Bar::x = 42;
print "$_,$Foo::{$_}\n" for keys %Foo::;
which outputs Bar::,*Foo::Bar::, demonstrating that %Foo::Bar:: is a sub-stash of %Foo::. Notably, %main:: is a sub-stash of the root stash %::, but as both refer in fact to the same stash, that implies that you need to be careful if you ever want to recursively walk the stashes.
Another interesting stash is %CORE::GLOBAL::, where live the subroutines that override perl keywords.
Quick, hide your stash, the cops are coming! (Score:3, Funny)
-Dom
Reply to This
Re:Quick, hide your stash, the cops are coming! (Score:3, Funny)
kudos (Score:1)
perlglos (Score:1)
Re:perlglos (Score:1)
---ict / Spoon
treasures in blog (Score:1)