in reply to RE: Parsing a file one line at a time
in thread Parsing a file one line at a time

you (probably) might want to use some idomatic perl, its called 'slurp mode'. It means being able to take in (slurp) the whole file in one go, this is possible by temporarily 'undef'ining the File Seperator $\.
open(FILE1, $ARGV[0]) || die "Error: $!\n"; { local $/; #value is restored at end this block undef $/; #'slurp mode' @lines = <FILE1>; #slurp all lines } #$/ is as back 'to normal', so nothing unexpected happens later
local is 'sometimes' the 'right' way.

Replies are listed 'Best First'.
(Ovid) RE(3): Parsing a file one line at a time
by Ovid (Cardinal) on Jul 23, 2000 at 21:17 UTC
    Actually, "slurp" mode is used for reading the contents of a file into a scalar. You're using an array. If you assign a filehandle to an array, Perl just "understands" and reads the entire file into the array. This code works fine:
    open(FILE1, $ARGV[0]) || die "Error: $!\n"; @lines = <FILE1>;
    Cheers,
    Ovid