Careful.
foreach expands the bracketed list first so you still slurp the file. You only sidestep the declaration of a temporary array variable. Your code will however work
exactly as intended - without the need for
any other modifications - if you simply substitute
foreach for
while.
Makeshifts last the longest.