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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.