簡體   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