On Apr 19, Eric Beaudoin said:
>while (<INFILE>) {
> for (my $i = 1; $i <= 9; $i++) {
> # print the courent line (store in $_)
> print OUTFILE;
> # exit the loop if no more lines
> last if eof;
> # read the next line
> $_ = <INFILE>;
> }
>}
This code loses a line of the file for each block of nine lines read. The
reason is because after the NINTH line of the block is printed, you read
ANOTHER line, and then the while loop's conditional expression reads
another line.
To get around this, you can do:
CHUNK:
while (<INFILE>) {
for my $i (1 .. 9) {
last CHUNK if eof;
print OUTFILE;
$_ = <INFILE>;
}
redo;
}
Or something like:
until (eof INFILE) {
for my $i (1 .. 9) {
my $line = <INFILE>;
last if eof;
print OUTFILE $line;
}
}
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]