I tried to reproduce this on a later version of Perl (5.8.8) and couldn't. Here's the test I tried:
use Test::More 'tests' => 12; my $key = 'key'; my $encoded_key = $key; utf8::upgrade( $encoded_key ); ok( utf8::is_utf8( $encoded_key ), 'encoded key is utf8' ); ok( ! utf8::is_utf8( $key ), 'unencoded key is not utf8' ); ok( $key eq $encoded_key, 'key eq encoded_key' ); # I don't know why these would have changed, # but I'm checking anyway. ok( utf8::is_utf8( $encoded_key ), 'encoded key is utf8' ); ok( ! utf8::is_utf8( $key ), 'unencoded key is not utf8' ); is( $key, $encoded_key, 'key is encoded_key' ); ok( utf8::is_utf8( $encoded_key ), 'encoded key is utf8' ); ok( ! utf8::is_utf8( $key ), 'unencoded key is not utf8' ); my %via_var = ( $key => 'value' ); my %hardcode = ( 'key' => 'value' ); is( $via_var{$key}, 'value', 'Can access hash via $key' ); is( $via_var{$encoded_key}, 'value', 'Can access hash via $encoded_key' ); is( $hardcode{$key}, 'value', 'Can access hardcoded hash via $key' ); is( $hardcode{$encoded_key}, 'value', 'Can access hardcoded hash via $encoded_key' );
I wonder if there's some difference between the version you have and the version I have, so I wonder if that test does the same thing for you that it does for me. I get the same results regardless of whether I have use utf8 at the top.
In reply to Re: hard-coded hash return nothing for utf-8 string
by kyle
in thread hard-coded hash return nothing for utf-8 string
by vic
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |