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

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

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
June 30, 2013 07:04
Subject:
[perl #118701] __PACKAGE__ does not work as a hash key
Message ID:
rt-3.6.HEAD-23766-1372575853-776.118701-15-0@perl.org
On Sat Jun 29 23:53:13 2013, jimav wrote:
> 
> 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

That’s because hash keys auto-quote.  You have to write
$table{+__PACKAGE__}, $table{(__PACKAGE__)} or something similar.

The same applies, e.g., to $table{time}, which will use "time" rather
than "1372575833" as the hash key.

That’s a feature. :-)

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=118701

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