in reply to Reading files n lines a time
Consider this solution:
Tie::File lets you play with files as if they were arrays and is part of the standard Perl distribution.#!/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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reading files n lines a time
by Kenosis (Priest) on Dec 06, 2012 at 17:19 UTC |