I have code which loops through lines in a file, and tries to print out each line with something added at the start and end.
However, I get output like this: “nominalte cows”.
Basically, the bit after the line (nominal) overwrites the start of it. I know that removing the chomp and regex lines stops this effect, but I need it to be on one line without spaces. Where am I going wrong?
while ($line = <INPUT>) {
chomp $line;
$line =~ s/ //g;
printf "\@attribute %s nominal\n", $line;
}
Your input file is probably from MS Windows with end of line encoded as CR-LF. You can also just
s/\r//to remove the CR.