The foreach statement causes <DATA> to be evaluated in list context, hence all data is read at once. Subsequent reads obviously fail by lack of data.
This is easy to see by replacing the foreach $line (<DATA>) { by while ($line = <DATA>) { which does what you expected.
hope this helps, -gjb-
In reply to Re: Trying to read a filehandle inside a loop
by gjb
in thread Trying to read a filehandle inside a loop
by roik
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |