in reply to Re: Continuing While Loop One Iteration After EOF
in thread Continuing While Loop One Iteration After EOF

Good suggestion, but I don't think it fits the bill. continue is ran on each iteration - I just want to run the loop one last time, from the top, after the last line in the file is processed.

Replies are listed 'Best First'.
Re^3: Continuing While Loop One Iteration After EOF
by blazar (Canon) on Dec 22, 2005 at 09:59 UTC
    Then redo is just for that! Unfortunately you can't use it as simply as in
    redo if 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:
    my ($i,$cnt); while (<$inhandle>) { print ++$i; last if $cnt; $cnt++, 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:
    for (<$infile>,'AFTERFILE') { ... }