Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Unicode strange behaviour as a key of hash

by leszekdubiel (Scribe)
on Aug 14, 2017 at 17:34 UTC ( [id://1197369]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1197369]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2024-04-23 10:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found