Perl output is overwritten

I have code that iterates over lines in a file and tries to print each line with something added at the beginning and end.

However, I get the conclusion as follows: "rated cows."

Basically, a bit after a line (nominal) overwrites its beginning. I know that deleting the chomp and regex lines stops this effect, but I need it to be on the same line without spaces. Where am I mistaken?

while ($line = <INPUT>) { chomp $line; $line =~ s/ //g; printf "\@attribute %s nominal\n", $line; } 
+6
source share
2 answers

Your input file is probably from MS Windows with the end of the line encoded as CR-LF. You can also just s/\r// remove the CR.

+10
source

Your variable may have \r . Try using \s :

 $line =~ s/\s//g; 

See perlre for the value of \s .

+6
source

Source: https://habr.com/ru/post/901224/


All Articles