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

Constants as keys in hash initialization

Thread Next
From:
Tim Peoples
Date:
May 13, 2003 01:02
Subject:
Constants as keys in hash initialization
Message ID:
20030512164950.A12434@toolman.org

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 constant.pm), 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... :-)

Tim.

-- 
 _______________________________________________________________________  
                                                      Timothy E. Peoples
                                                   Have Camel, Will Code
                                                         tim@toolman.org


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About