http://www.perlmonks.org?node_id=1007591


in reply to Reading files n lines a time

Consider this solution:

#!/usr/bin/perl -w ###################################################################### +## use strict; use Tie::File; tie my @fin,"Tie::File","multilines.txt" or die $!; for(my $ix=0;$ix <= $#fin;$ix+=4){ my @lines=(); foreach (my $iy=0;($iy < 4) && (($ix+$iy)<=$#fin);$iy++){ push @lines, $fin[$ix+$iy]; } printf "Lines starting with line %d:\n%s\n\n",$ix+1,join("\n",@lin +es); } untie @fin;
Tie::File lets you play with files as if they were arrays and is part of the standard Perl distribution.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg