in reply to How to remove all new line ?
You are putting new line characters back with your print inside the loop. The loop handles one line at a time - it doesn't slurp the whole file. Probably the best fix is to move the print of the newline to after the read loop:
open my $inData, '<', $tmpfile or die "Can't open $tmpfile: $!"; while (defined (my $data = <$inData>)) { chomp $data; print $data; } close $inData; print "\n";
Note the use of the three parameter version of open and the result checking using die. Note too the use of a lexical for the file handle and that you don't need to interpolate the file name into a string.
If you are assigning to a variable in the while loop condition you need to use defined to make the same test that Perl's magic while (<fh>) handling makes for you.
The chomp should be all you need to strip line separators, but watch out for OS differences in line endings (if that is an issue).
|
|---|