IO :: File-> open()は、次のプログラムでのopen()の使用を尊重していないようです。これは私には奇妙で、ドキュメントに反しているようです。または多分私はそれを間違っています。IO::Fileを使用しないようにコードを書き直すのは難しいことではありません。
出力は次のようになると思います
$VAR1 = \"Hello \x{213} (r-caret)";
Hello ȓ (r-caret)
Hello ȓ (r-caret)
Hello ȓ (r-caret)
しかし、このエラーが発生します:「おっと:./run.plの33行目に印刷中の不正な形式のUTF-8文字(文字列の予期しない終わり)」。
それは私にはまったく正しくないようです。
#!/usr/local/bin/perl
use utf8;
use v5.16;
use strict;
use warnings;
use warnings qw(FATAL utf8);
use diagnostics;
use open qw(:std :utf8);
use charnames qw(:full :short);
use File::Basename;
my $application = basename $0;
use Data::Dumper;
$Data::Dumper::Indent = 1;
use Try::Tiny;
my $str = "Hello ȓ (r-caret)";
say Dumper(\$str);
open(my $fh, '<', \$str);
print while ($_ = $fh->getc());
close($fh);
print "\n";
try {
use IO::File;
my $fh = IO::File->new();
$fh->open(\$str, '<');
print while ($_ = $fh->getc());
$fh->close();
print "\n";
}
catch {
say "\nOops: $_";
};
try {
use IO::File;
my $fh = IO::File->new();
$fh->open(\$str, '<:encoding(UTF-8)');
print while ($_ = $fh->getc());
$fh->close();
print "\n";
}
catch {
say "\nOops: $_";
};