Perl哈希键仅在紧接着换行符时打印

Mar*_*use 1 printing perl hash key

也许我是愚蠢的,但这对我来说没有意义......我通过从众多文件中读取唯一代码和错误代码来构建哈希.当我尝试打印出key = value对时,除非紧接着是换行符,否则键不会出现.

这是代码:

foreach my $key (keys %codehash){
    print "Key: $key\tValue: $codehash{$key}\n";
    print "Key: $key\n";
    print "Value: $codehash{$key}\n";
    print "\n\n";
}
Run Code Online (Sandbox Code Playgroud)

这是输出:

         Value: NoParamSpecified
    Key: 016C
    Value: NoParamSpecified


        Value: billingAddress.firstName.lengthLong
    Key: 003M
    Value: billingAddress.firstName.lengthLong


         Value: billingAddress.address1.lengthLong
    Key: 0041
    Value: billingAddress.address1.lengthLong
Run Code Online (Sandbox Code Playgroud)

请注意,它甚至不打印第一个语句中的"Key:"纯文本,只显示选项卡及更高版本.我以前从未见过这个.

Zai*_*aid 7

该行为与包含"\r"末尾的所有键一致.十六进制转储将确认这一点.

确认这一点的另一种方法是在打印出来之前在键上运行合适的正则表达式替换:

$key =~ s/\s+$//;
Run Code Online (Sandbox Code Playgroud)