Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: read file into 1 line string

by davido (Cardinal)
on Apr 21, 2012 at 15:20 UTC ( [id://966376]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://966376]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-26 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found