In Perl, how to remove ^M from a file?

后端 未结 10 1829
臣服心动
臣服心动 2020-12-28 13:51

I have a script that is appending new fields to an existing CSV, however ^M characters are appearing at the end of the old lines so the new fields end up on a n

10条回答
  •  盖世英雄少女心
    2020-12-28 14:48

    To convert DOS style to UNIX style line endings:

    for ($line in ) {
       $line =~ s/\r\n$/\n/;
    }
    

    Or, to remove UNIX and/or DOS style line endings:

    for ($line in ) {
       $line =~ s/\r?\n$//;
    }
    

提交回复
热议问题