I am rewriting some of my old one-liners that grew into oft-used utilities. Whilst doing so, I wanted to move a lot of hard-coded strings (pathnames and such) into constants at the top of the script (via the
constant
pragma). So, I type:
use constant CONST => {
foo => 'bar',
fiz => 'baz'
foreach (keys CONST)
print "$_\n";
This, of course, returned the error:
Type of arg 1 to keys must be hash (not constant item)
"Owe," I thought, and I changed it to:
foreach (keys %{CONST})
print "$_\n";
This resulted in the error:
Variable "%CONST" is not imported
Hmmmmmm....
print CONST;
printed
HASH(0x1a9de10)
, which is what I expected. What I did not expect is that I could not access it.
Can someone please enlighten me? In the meantime, I guess I'll try various dereferencing combinations and read up on
constant
and
perlref
.
Thanks,
Jeremy
PerlMonks somehow became entangled with The Perl Foundation . Donate to TPF!
Wonderful Web Servers and Bandwidth Generously Provided by pair Networks
Built with the Perl programming language .