reading in a file, line by line by picking certian lines

reading in a file, line by line by picking certian lines

Post by patrick.j. » Sat, 21 Jun 2008 22:06:24


Hi all

I am looking at a way of reading a line doing a regex to find the
specific line then pick out the line, sudo code would be some thing
like the following:

read in line
check regex

if regex is correct
{ jump 10 lines
print the output
}

any ideas on jumping the 10 lines, how do I ignore the lines in the
file, and know I'm going the right distance ?

Thanks
Pat
 
 
 

reading in a file, line by line by picking certian lines

Post by chas.owen » Sat, 21 Jun 2008 22:30:13


snip

while (<>) {
if (/regex/) {
<> for 1 .. 9; #throw away nine lines
my $line = <>; #get the tenth line
print $line;
}
}

--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

 
 
 

reading in a file, line by line by picking certian lines

Post by krahn » Sun, 22 Jun 2008 02:30:08


Hello,


Here is another way to do it:

my $jump;
while ( <FILE> ) {
$jump = $. + 10 if /regex/;
print "the output" if $jump == $.;
}


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
 
 
 

reading in a file, line by line by picking certian lines

Post by rsarp » Sun, 22 Jun 2008 04:26:30

> I am looking at a way of reading a line doing a regex to find the


I don't know how big your file is but you can try Tie::File...it's a
core module...it works for big files, you can do regex, easy to go/
treat a particular line, etc...
http://www.yqcomputer.com/


my two cents,
 
 
 

reading in a file, line by line by picking certian lines

Post by baxter.bra » Mon, 23 Jun 2008 00:14:49


Two observations:
1. this will warn while $jump is undef
2. if regex is matched by one of the ten 'skip' lines, it will skip
some more
 
 
 

reading in a file, line by line by picking certian lines

Post by patrick.j. » Mon, 23 Jun 2008 21:05:24

Hi all
Thanks for all the help with this, going to have some fun implementing it :)

Thanks
Pat