为什么我会在这里与Devel :: Peek ::转储两个不同的结果?
#!/usr/bin/env perl use warnings; use 5.014; use utf8; binmode STDOUT,':encoding(utf-8)'; use Devel::Peek; my %hash1 = ( 'müller' => 1 ); say Dump $_ for keys %hash1; my %hash2; $hash2{'müller'} = 1; say Dump $_ for keys %hash2;
输出:
SV = PV(0x753270) at 0x76d230 REFCNT = 2 FLAGS = (POK,pPOK,UTF8) PV = 0x759750 "m\303\274ller"\0 [UTF8 "m\x{fc}ller"] CUR = 7 LEN = 8 SV = PV(0x753270) at 0x7d75a8 REFCNT = 2 FLAGS = (POK,FAKE,READONLY,pPOK) PV = 0x799110 "m\374ller" CUR = 6 LEN = 0
解决方法
这两个标量都包含完全相同的字符串.唯一的区别只在于如何在内部存储字符串.
我的猜测是,密钥被规范化,以便在尝试在哈希中找到密钥时使比较更容易.