in reply to read file into 1 line string

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^2: read file into 1 line string
by davido (Cardinal) on Apr 21, 2012 at 15:20 UTC
    $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

Re^2: read file into 1 line string
by nemesdani (Friar) on Apr 21, 2012 at 12:55 UTC
    I don't understand one thing: Why do you specify an elsif? Wouldn't a plain elsebe sufficient?


    I'm too lazy to be proud of being impatient.

      It would be totally sufficient.

      Another thing I don't get is why even check for empty string? How is that relevant?