enoch has asked for the wisdom of the Perl Monks concerning the following question:
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:
This, of course, returned the error:use constant CONST => { foo => 'bar', fiz => 'baz' }; foreach (keys CONST) { print "$_\n"; }
Type of arg 1 to keys must be hash (not constant item)
"Owe," I thought, and I changed it to:
This resulted in the error:foreach (keys %{CONST}) { print "$_\n"; }
Hmmmmmm....print CONST; printed HASH(0x1a9de10), which is what I expected. What I did not expect is that I could not access it.Variable "%CONST" is not imported
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
|
---|
Replies are listed 'Best First'. | |
---|---|
(ar0n) Re: Accessing Constant Hashes
by ar0n (Priest) on Jan 16, 2002 at 02:27 UTC | |
by enoch (Chaplain) on Jan 16, 2002 at 02:32 UTC | |
by Ovid (Cardinal) on Jan 16, 2002 at 03:14 UTC | |
by ar0n (Priest) on Jan 16, 2002 at 02:43 UTC | |
by larryk (Friar) on Jan 16, 2002 at 16:44 UTC | |
Re: Accessing Constant Hashes
by perrin (Chancellor) on Jan 16, 2002 at 02:36 UTC | |
by lestrrat (Deacon) on Jan 16, 2002 at 02:46 UTC |
Back to
Seekers of Perl Wisdom