Think about Loose Coupling | |
PerlMonks |
Re^2: read file into 1 line stringby davido (Cardinal) |
on Apr 21, 2012 at 15:20 UTC ( [id://966376]=note: print w/replies, xml ) | Need Help?? |
$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
In Section
Seekers of Perl Wisdom
|
|