Here's a simple way to do it using modulo chunksize on the line number $.
use strict; use warnings; my $fname = shift or die "usage: $0 fname\n"; open(my $fh, '<', $fname) or die "error: open '$fname': $!"; my $chunksize = 4; my $chunk = ""; while ( my $line = <$fh> ) { $chunk .= $line; next if $. % $chunksize; print "---chunk---\n$chunk"; $chunk = ""; } close $fh; if (length $chunk) { print "---chunk (leftover)---\n$chunk"; }
In reply to Re: Reading files n lines a time
by eyepopslikeamosquito
in thread Reading files n lines a time
by naturalsciences
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |