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

Hmmmm... sure... Actually I spent 2 minutes to understand your post, before I could see the "..." after the while block. Indeed, I keep with the $i-- solution...

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

Replies are listed 'Best First'.
Re^4: Continuing While Loop One Iteration After EOF
by ikegami (Patriarch) on Dec 21, 2005 at 18:13 UTC
    Well, in reality, it will be
    while (<INHANDLE>) { dfkahsfkasdkfjhasdklfa; dsfjasd jf; lsdfj asdljf; } continue { if (eof(INHANDLE)) { dfkahsfkasdkfjhasdklfa; dsfjasd jf; lsdfj asdljf; } }

    vs

    while (<INHANDLE>) { dfkahsfkasdkfjhasdklfa; dsfjasd jf; lsdfj asdljf; } dfkahsfkasdkfjhasdklfa; dsfjasd jf; lsdfj asdljf;

    But that's completely misses what I meant to point out. It sounds like the OP wanted to avoid code duplication (or else, he'd would simply have used the second snippet), but your code doesn't do that.

      If avoiding code duplication is the goal, put the code that exists within the while loop into a subroutine, and call that sub one more time after the loop. If he wants to get tricky, he could generate a callback routine as a closeure within the loop that gets executed after the loop, though that seems like a lot of complexity that may lack justification.


      Dave

      Hmm? I agree that the "continue" solution is pointless... But is the other solution too?

      my $i = 1; while ((my $line = <INHANDLE>) || $i--) { dfkahsfkasdkfjhasdklfa; dsfjasd jf; lsdfj asdljf; }
      daniel