in reply to What’s the difference between iterating over a file with foreach or while in Perl?
Is there a difference ...?
Yes, the foreach will read the entire file into memory before it starts to '# do something', while the while will process the file line by line (unless you've changed the default input record separator $/). In the foreach case, the <FILE> is evaluated in list context, in the while case in scalar context.
|
|---|