in reply to Continuing While Loop One Iteration After EOF

If you recognise that the body of the while loop is effectively a subroutine with implicit parameters, then it becomes natural to think of what you describe as (crudely):

doBody( $_ ) while( <FILEHANDLE> ); doBody( undef );

Which makes it clear that

  1. you are calling (some part(s) of) the body from two different locations;
  2. you want the body to take different actions dependent up when it is called;

    Ie. When processing the file, or afterwards.

  3. Your "$_ == NULL" is a flag used just to decide when to do which type of processing.

That probably indicates that there is some subset of the processing inside the body of the loop that should really be factored into a separate subroutine, rather than inlined. Leading to

while( <FILEHANDLE> ) { do some stuff; doTheFactoredStuff(); do some other stuff; } doTheFactoredStuff();

Which may suggest a better way of doing things--or not:)


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Continuing While Loop One Iteration After EOF
by jcc (Sexton) on Dec 21, 2005 at 18:34 UTC
    Thanks everyone for the replies. Functionally, the subroutine path does make good sense and probably should be the way to implement this.
    Procedurely, ikegami's earlier suggestion with the for(;;){} construct worked like a charm. Thanks again to all.