Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of rafael (2125)

Thursday June 19, 2003
07:22 AM

The Perl Jargon : Stashes

[ #12944 ]
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;
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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.