in reply to Continuing While Loop One Iteration After EOF

What's wrong with:
while(( $_ = <INHANDLE>) || ($_ = 'AFTERFILE') ){ stuff; }
Assuming, as you imply, that the body of the loop will know what to do when it sees AFTERFILE.

Replies are listed 'Best First'.
Re^2: Continuing While Loop One Iteration After EOF
by Corion (Patriarch) on Dec 22, 2005 at 10:18 UTC

    You should beware of lines like 0 at the end of the file, without a newline :-) But that's about the only thing that can fail for this approach...

Re^2: Continuing While Loop One Iteration After EOF
by Eimi Metamorphoumai (Deacon) on Dec 22, 2005 at 16:57 UTC
    That will loop through the file, but then it will continue to loop forever with 'AFTERFILE' in $_. So if you're going to do that, you'd have to do it as
    while (defined($_ = <INHANDLE>) || ($_ = "AFTERFILE")){ stuff; last if $_ eq "AFTERFILE"; }
    and of course, if the file actually contains AFTERFILE, you're in trouble.

    So if you don't mind undef as your special after loop value, it's probably easiest to do something like

    LOOP: { $_ = <>; stuff; redo LOOP if defined; }
      The OP suggested AFTERFILE and that's why I said "Assuming, as you imply, that the body of the loop will know what to do when it sees AFTERFILE."