in reply to Continuing While Loop One Iteration After EOF

What about continue?

Checkingthe perldocs (perldoc perlsyn; look for "continue"), it looks like it may be what you need.

  • Comment on Re: Continuing While Loop One Iteration After EOF

Replies are listed 'Best First'.
Re^2: Continuing While Loop One Iteration After EOF
by jcc (Sexton) on Dec 21, 2005 at 17:23 UTC
    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.
      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') { ... }