in reply to Re: read file into 1 line string
in thread read file into 1 line string
$data .=chomp($_);
anish_batra's solution is broken. chomp has as its return value the number of characters chomped from its parameter. You're appending a chomp-count to $data rather than the line that was just read from the filehandle.
The rest of the solution is just a mess.
Don't read a filehandle inside of a foreach like that. Don't specify elsif to negate the base condition; that's what else does. Don't bother testing whether the line is blank; allowing an empty string to be appended doesn't hurt anything. And where is the test for open failure?
Unless there's a specific reason to use them, bareword typeglob filehandles and two-arg open have largely drifted out of favor as well.
Dave
|
|---|