繁体   English   中英

将 UTF-8 Unix LF.dat 文件转换为 UTF-8 编码的 CR LF.dat 文件使用 Z0114AD06D728F198EFA434

[英]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);  
}

binmode中指定:crlf crlf 层

binmode DES, ':crlf';

print不能只带句柄,它还需要知道要打印什么:

 print DES $_;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM