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
Back to
Seekers of Perl Wisdom