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

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

Thread Previous | Thread Next
From:
James E Keenan
Date:
June 30, 2013 12:06
Subject:
Re: [perl #118701] __PACKAGE__ does not work as a hash key
Message ID:
20130630120554.10498.qmail@lists-nntp.develooper.com
On 6/30/13 2:53 AM, Jim Avera wrote:
> # New Ticket Created by  Jim Avera
> # Please include the string:  [perl #118701]
> # in the subject line of all future correspondence about this issue.
> #<URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=118701>
>
>
>
> This is a bug report for perl from james_avera@yahoo.com,
> generated with the help of perlbug 1.39 running under perl 5.14.2.
>
>
> -----------------------------------------------------------------
> #!/usr/bin/perl
> use strict; use warnings;
>
> sub show($) { defined($_[0]) ? ("'".$_[0]."'") : "undef" }
>
> my %table = ( main =>  "the-value" );
>
> warn "__PACKAGE__ = ",show(__PACKAGE__),"\n";
> warn "table{__PACKAGE__} = ", show($table{__PACKAGE__}), "\n";
> warn "table{'main'} = ", show($table{'main'}), "\n";
>
> die "bug" unless show($table{__PACKAGE__}) eq show($table{main});
> # This dies
>

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?

Thank you very much.
Jim Keenan

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