develooper Front page | perl.perl5.porters | Postings from May 2003

Constants as keys in hash initialization

Thread Next
Tim Peoples
May 13, 2003 01:02
Constants as keys in hash initialization
Message ID:

I was going to submit this as a perlbug but then thought perhaps it warrants
a little discussion.  Besides, there's already [perl #7130] that covers
most of this.

Given the following:

    use constant FOO => 'bar';

    my %hash = ( +FOO => 'foobar' );

...then keys(%hash) := ('FOO') and not ('bar').

One would think the unary '+' might force evaluation of the bareword
'FOO' into '&FOO' but it doesn't.

Of course (as mentioned in, C<FOO()> and C<FOO, 'foobar'>
(as well as C<&FOO>) all work as expected.

But, since C<$hash{+FOO}> is convention...  I just want it to DWIM... :-)


                                                      Timothy E. Peoples
                                                   Have Camel, Will Code

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About