Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Reading files n lines a time

by blue_cowdawg (Monsignor)
on Dec 06, 2012 at 14:50 UTC ( #1007591=note: print w/ replies, xml ) Need Help??


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


Comment on Re: Reading files n lines a time
Download Code
Replies are listed 'Best First'.
Re^2: Reading files n lines a time
by Kenosis (Priest) on Dec 06, 2012 at 17:19 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007591]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2015-07-29 20:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (267 votes), past polls