Perl: After Chomping a string, it does not print the string's value

前端 未结 1 1198
闹比i
闹比i 2021-01-21 19:00

So I am currently trying to write a perl script that reads to a file and writes to another. Currently, the problem that I have been having is removing new line characters from p

相关标签:
1条回答
  • 2021-01-21 19:36

    Your lines end with CR LF. You remove the LF, leaving the CR behind. Your terminal is homing the cursor on CR causing the next line output to overwrite the last line output.

    $ perl -e'
       print "XXXXXX\r";
       print "xxx\n";
    '
    xxxXXX
    

    Fix your input file

    dos2unix file
    

    or remove the CR along with the LF.

    s/\s+\z//   # Instead of chomp
    
    0 讨论(0)
提交回复
热议问题