Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 new row instead of the same one. How do I remove ^M characters from a CSV file using Perl?

like image 335
Alex Wong Avatar asked Mar 16 '09 14:03

Alex Wong


1 Answers

^M is carriage return. You can do this:

$str =~ s/\r//g 
like image 171
Can Berk Güder Avatar answered Oct 07 '22 09:10

Can Berk Güder