I decided to begin a series of posts about some of the interesting words of the Perl jargon.
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;This small snippet outputs x,*Foo::x,42.
print "$_,$Foo::{$_},${$Foo::{$_}}\n" for keys %Foo::;
Note that stashes can live in other stashes, as demonstrated by the following code :
$Foo::Bar::x = 42;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.
print "$_,$Foo::{$_}\n" for keys %Foo::;
Another interesting stash is %CORE::GLOBAL::, where live the subroutines that override perl keywords.
-Dom
Re:Quick, hide your stash, the cops are coming!
rafael on 2003-06-19T13:17:24
And indeed : next week, we'll speak about cops in perl. (Not kidding.)
Re:perlglos
koschei on 2003-06-20T00:02:06
Should probably submit that to p5p or perl-documentation@perl.org --- I think a filled out version would be good for the core pod.