http://qs321.pair.com?node_id=748843


in reply to Re: Hmmm: while(), file handle and $_ gotcha
in thread Hmmm: while(), file handle and $_ gotcha

moritz:

OK, that explains it. (I had an incorrect mental model: I was thinking that <FH> always put the data somewhere, using $_ unless otherwise specified. I don't know how I came to think that, as in hindsight that would be clearly stupid. Oh, well--live and learn!)

So the correct fix to my program would is to change the inner loop from:

for my $cnt (0 .. 3) { my $t=<DATA>; print $t; }

to

for my $cnt (0 .. 3) { $_=<DATA>; print; }

so I can avoid unnecessary variables and clutter.

Thank you!

...roboticus