[英]Perl read .DAT file with UTF-8 BOM format and write it with UTF-8 format without BOM
[英]Convert UTF-8 Unix LF .dat file to UTF-8 encoded CR LF .dat file using Perl
I have an input.dat file with Unix LF encoding, I want my output file to be Windows CR LF with UTF-8 encoding using Perl. 目前這是我的代碼的外觀。 如何將 CR 添加到文件中的現有 LF 中?
sub encodeUTF8 {
my $ProcVars = $_[0];
my $src = $_[1];
my $des = $_[2];
# open source file for reading
open(SRC,'<',$src) or die $!;
# open destination file for writing
open(DES,'>',$des) or die $!;
binmode DES;
print("copying content from $src to $des\n");
while (<SRC>) {
s/^\N{BOM}// if $. == 1;
print DES;
}
close(SRC);
close(DES);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.