perlquestion
enoch
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:
<CODE>
use constant CONST => {
foo => 'bar',
fiz => 'baz'
};
foreach (keys CONST)
{
print "$_\n";
}
</CODE>
This, of course, returned the error:
<CODE>
Type of arg 1 to keys must be hash (not constant item)
</CODE>
<READMORE>
"Owe," I thought, and I changed it to:
<CODE>
foreach (keys %{CONST})
{
print "$_\n";
}
</CODE>
This resulted in the error:
<CODE>
Variable "%CONST" is not imported
</CODE>
Hmmmmmm....<CODE>print CONST;</CODE> printed <CODE>HASH(0x1a9de10)</CODE>, which is what I expected. What I did not expect is that I could not access it.<P>
Can someone please enlighten me? In the meantime, I guess I'll try various dereferencing combinations and read up on [constant] and [perlref].<BR><BR>Thanks,<BR>Jeremy