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

[perl #7840] Hash Behaviour differs v5.6.0 to v5.6.1

Thread Previous | Thread Next
From:
Michael G Schwern via RT
Date:
July 14, 2005 16:47
Subject:
[perl #7840] Hash Behaviour differs v5.6.0 to v5.6.1
Message ID:
rt-3.0.11-7840-117399.4.36865287905043@perl.org
> [paul.barry@itcarlow.ie - Tue Oct 23 22:13:02 2001]:
> 
> #! /usr/bin/perl -w
> 
> use strict;
> use 5.6.0;
> 
> use constant HASH_KEY1 => 100;
> use constant HASH_KEY2 => 200;
> 
> our %hash_desc = (
>         HASH_KEY1 => "This is hash key one",
>         HASH_KEY2 => "This is hash key two"
> );
> 
> foreach my $h_desc ( sort keys %hash_desc )
> {
>     print "$h_desc -> $hash_desc{$h_desc}\n";
> }
> 
> 
> When executed under 5.6.0 the output is:
> 
> 100 -> This is the hash key one
> 200 -> This is the hash key two
> 
> When executed under 5.6.1 the output is:
> 
> HASH_KEY1 -> This is the hash key one
> HASH_KEY2 -> This is the hash key two
> 
> 
> What gives?  Why won't hashes in 5.6.1 use constants properly?  (Please
> don't tell me that Perl 5.6.0 is wrong ... I just might cry.)

5.6.0 was wrong, sorry.  A lot of things about 5.6.0 were wrong.

$ perl5.4.5 -wle 'use constant FOO => 100;  %h = ( FOO => 42 );  print
$h{"FOO"}'
42
$ perl5.5.4 -wle 'use constant FOO => 100;  %h = ( FOO => 42 );  print
$h{"FOO"}'
42
$ perl5.6.2 -wle 'use constant FOO => 100;  %h = ( FOO => 42 );  print
$h{"FOO"}'
42
$ perl5.8.6 -wle 'use constant FOO => 100;  %h = ( FOO => 42 );  print
$h{"FOO"}'
42

=> is documented as follows:

 The => digraph is mostly just a synonym for the comma operator.  It's
 useful for documenting arguments that come in pairs.  As of release
 5.001, it also forces any word to the left of it to be interpreted as a
 string.

*Any* word, including one that might also be a constant, is interpreted
as a string.  %h = ( CONSTANT() => 42 );  is a work around.


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