John W. Krahn wrote:
You can't because perl implements constants using subroutines and subroutines
can only return a list.
Perl subroutines return only lists but it converts them to hashes
automatically:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
sub list_to_hash {
return qw( a 1 b 2 c 3 );
}
my %hash = list_to_hash();
print Dumper( \%hash );
__END__
The thing about constant is that does not create a true constant; it
creates a reference to an anonymous subroutine. You have to learn to use
it as such:
#!/usr/bin/perl
use strict;
use warnings;
use constant STOPWORDS => map { $_, 1 } qw(a about above across adj after);
for my $key ( sort keys %{ { STOPWORDS } } ){
my $value = ${ { STOPWORDS } }{$key};
print "$key => $value\n";
}
__END__
Interpretation:
%{ { STOPWORDS } } means create an anonymous hash from the list returned
by STOPWORDS and then dereference it.
${ { STOPWORDS } }{$key} means create an anonymous hash from the list
returned by STOPWORDS, dereference it, and get the value for $key.
--
Just my 0.00000002 million dollars worth,
--- Shawn
"Probability is now one. Any problems that are left are your own."
SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>