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:
Lukas Mai
Date:
July 2, 2013 03:47
Subject:
Re: [perl #118701] __PACKAGE__ does not work as a hash key
Message ID:
51D24D21.2070301@gmail.com
On 02.07.2013 00:42, Jim Avera wrote:
> 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?

Wrong part of the documentation. The above only means you can't say 
$__PACKAGE__::foo or similar. Jim isn't trying to construct a variable name.

> 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.

As Father Chrysostomos explained, hash keys always autoquote 
identifiers. Special-casing __PACKAGE__ would introduce another hidden 
gotcha, not eliminate it.

-- 
Lukas Mai <plokinom@gmail.com>

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