in reply to Re^2: Continuing While Loop One Iteration After EOF
in thread Continuing While Loop One Iteration After EOF
since eof will continue to hold true and you won't run the loop just one last time. You'll have to add some more custom control instead:redo if eof;
To add to the other suggestions you have been given and with a big caveat: we always recommend to always read files in line by line and not to slurp them in all at once. But if you're confident your input will not be exceedingly large in size and/or you collect all lines anyway, you may just do the latter:my ($i,$cnt); while (<$inhandle>) { print ++$i; last if $cnt; $cnt++, redo if eof; }
for (<$infile>,'AFTERFILE') { ... }
|
|---|