in reply to While.For loop noob query
What you are doing is keeping a one-line buffer. Read in the next line, if there is one, do your regular thing with the line in the buffer. If there's no next line, the thing in your buffer is the last line, so do your special thing then.if (defined (my $previous_line = <>)) { while (my $current_line = <>) { do_regular_thing_with $previous_line; $previous_line = $current_line; } do_special_thing_with $previous_line; }
No need to count lines.
|
|---|