我在调试变量名(或哈希键)为 UTF-8 字符串的 Perl 程序时遇到了麻烦。程序编译正常(并运行),但每当我想调试它时,调试器就很不高兴...
我在调试变量名(或哈希键)为 UTF-8 字符串的 Perl 程序时遇到了麻烦。程序编译正常(并运行),但每当我想调试它时,如果我需要使用变量/哈希键名,调试器就会对它们非常不满意。
这是一个(非常简单的)MWE:
use strict;
use utf8;
use warnings qw(FATAL utf8);
use open qw(:std :encoding(UTF-8));
use charnames qw(:full :short);
my $unité = 125;
my %hash = ( 'Quantité' => 18 );
printf "%d\n", $unité*$unité;
printf "%d\n", $hash{Quantité};
运行时没有问题:
$ perl test.pl
15625
18
但是在调试的时候,调试器却很难过:
$ perl -d test.pl
Loading DB routines from perl5db.pl version 1.77
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
HistFile = '/home/XXX/.perldb.hist'
Éxécution afterinit
main::(test.pl:10): my $unité = 125;
DB<100> n
main::(test.pl:11): printf "%d\n", $unité*$unité;
DB<100> p $unité
Unrecognized character \xC3; marked by <-- HERE after T} $unit<-- HERE near column 120 at (eval 10)[/usr/lib64/perl5/5.38/perl5db.pl:742] line 2.
at (eval 10)[/usr/lib64/perl5/5.38/perl5db.pl:742] line 2.
eval 'no strict; ($@, $!, $^E, $,, $/, $\\, $^W) = @DB::saved;package main; $^D = $^D | $DB::db_stop;
print {$DB::OUT} $unité;
' called at /usr/lib64/perl5/5.38/perl5db.pl line 742
DB::eval called at /usr/lib64/perl5/5.38/perl5db.pl line 3451
DB::DB called at test.pl line 11
那么,我如何访问一个 UTF8 命名的变量(与哈希键有同样的问题)?