leszekdubiel has asked for the wisdom of the Perl Monks concerning the following question:

Could anyone tell why the program displays "error 2"? This shouldn't display any error... nor first nor second.
#!/usr/bin/perl -CSDA use utf8; use strict; use warnings; my %h; $h{'Góry'} = 1; 'Góry' =~ /\A[[:alnum:]]*\z/ or die "error 1"; for (keys %h) { $_ =~ /\A[[:alnum:]]*\z/ or die "error 2"; }
Leszek Dubiel

Replies are listed 'Best First'.
Re: Unicode strange behaviour as a key of hash
by dave_the_m (Monsignor) on Aug 14, 2017 at 19:05 UTC
    It appears to be a bug the optimisation of constant hash keys. The constant key string in $h{'Góry'} is being downgraded from utf8, whereas if you write my $g = 'Góry'; $h{$g} = 1; it works ok. Once the key is downgraded, you then run into the Unicode Bug. This can bypassed in pattern matches using the //u match modifier.

    Dave.