in reply to Re^2: Avoid using local $/=undef?
in thread Avoid using local $/=undef?

"The second block of code is what I wrote, thinking it better practice to not read/process the entire file at once."

That is usually correct, although there are sometimes (in my experience very rare) occassions where reading an entire file into memory allows better processing / data-munging / manipulation, etc... perhaps to avoid having to seek forwards/backwards through a file and simply just shove it into memory.

(untested:) I don't think there is any real significant performance gain/tradeoff with either solution, unless you need to read non-contiguous chunks of data repeatedly/excessively - then the all-in-memory option will be better.

But if you're only ever interested in the current "line" or "$/" chunk of data, then the line-by-line processing method will likely only ever need a couple of MB of memory, whereas the entire file in memory will require space proportionate to the size of the file, and limit you to the amount of RAM you've got available to use.