develooper Front page | perl.perl5.porters | Postings from July 2013

Re: [perl #118701] __PACKAGE__ does not work as a hash key

Thread Previous | Thread Next
From:
Jim Avera
Date:
July 1, 2013 22:42
Subject:
Re: [perl #118701] __PACKAGE__ does not work as a hash key
Message ID:
51D205C5.1060407@yahoo.com
On 06/30/2013 05:06 AM, James E Keenan via RT wrote:
> This limitation has been documented in 'perlmod' since 1997: 
> ##### The special symbol C<__PACKAGE__> contains the current package, 
> but cannot (easily) be used to construct variable names. ##### Is 
> there any compelling reason why we should alter this long-standing 
> behavior?

At this point in Perl's history not much is really compelling, so I 
guess the answer is no.

But still, perldata says __PACKAGE__ etc. are "special literals" which 
may (only) be used as "separate tokens".  That makes it sound like they 
are recognized while scanning regardless of the context.

I found this the hard way (i.e. as a silent bug) when $hash{__PACKAGE__} 
interpreted __PACKAGE__ as a bareword or unquoted string, rather than as 
a special literal token.  It's another "hidden gotcha" which would be 
nice to eliminate.

-Jim

Thread Previous | 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