我有一个简单的 Perl 脚本,可以比较两个文件。结果我用 UTF8 BOM 编码写入不同的文件。为了将文本保存在 BOM 文件中,我将 chr(65279) 打印到结果文件的开头。有时输入文本在文本的乞求中已经包含 BOM 字符,而我的脚本又打印了一个。
问题是:我如何才能解决它不打印此 BOM 字符两次。
请参阅下面我的 Perl 代码的文本:
use strict;
use warnings;
use List::Compare;
use Cwd 'abs_path';
use open ':encoding(utf8)';
use open IO => ':encoding(utf8)';
open F, "<$ARGV[0]" or die $!;
open S, "<$ARGV[1]" or die $!;
my @a=<F>;
my @b=<S>;
close F;
close S;
my $lc = List::Compare->new(\@a, \@b);
my @intersection = $lc->get_intersection;
my @missing = $lc->get_unique;
my @extra = $lc->get_complement;
open EXTRA, ">".$ARGV[2]."file_extra.txt" or die("Unable to open the file");
open MISSING, ">".$ARGV[2]."file_missing.txt" or die("Unable to open the file");
open SUBTRACTED, ">".$ARGV[2]."file_subtr.txt" or die("Unable to open the file");
#Turn on UTF-8 BOM support
print EXTRA chr(65279);
print MISSING chr(65279);
print SUBTRACTED chr(65279);
print MISSING @missing;
print EXTRA @extra;
print SUBTRACTED @intersection;
close MISSING;
close EXTRA;
close SUBTRACTED;