I have a file that reads like this:
dog cat mouse
apple orange pear
red yellow green
There is a tab \t
separating the words on each row, and a newline \n
separating each of the rows. Below the last line, red yellow green
there is a blank line due to a newline \n
after green
.
I would like to use Perl to remove the newline.
I have seen a few articles like this How can I delete a newline if it is the last character in a file? that give solutions for Perl, but I would like to do this in hard code so that I can incorporate it into my Perl script. I don't know if this might be possible using chomp, or if chomp works on each line separately (I would like to keep the newline between lines).
Also I have seen previously comments that suggest maintaining a newline at the end of a file because Unix commands work better when a file ends with a newline. However, I have created a script which relies on input files not ending with a newline, therefore I really feel removing the newlines is necessary for my work.