Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
How do I process lines in a file from the point where a line contains a certain word ?
I have a file that I wish to process. e.g.
I can't use seek because I don't know how many lines will be in the file and at what position the "internal name" first appears.
I tried doing something like this but it doesn't work
These are variable length records per line and the file is a variable number of lines long.
Any help appreciated
I have a file that I wish to process. e.g.
I want to start processing the file where the line begins with "internal name". After this I only want to process the lines that have "need this" in them until end of file. Where "need this" always occurs at the beginning of the line.a line another line internal name another line a further line need this another line need this
I can't use seek because I don't know how many lines will be in the file and at what position the "internal name" first appears.
I tried doing something like this but it doesn't work
This doesn't work because each time round the loop it searches for "internal name".open DATA,filename; while (<DATA>) { chomp; next unless (/^internal name/); next unless (/^need this/); do something with data } close DATA;
These are variable length records per line and the file is a variable number of lines long.
Any help appreciated
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: seek and process from there on
by blazar (Canon) on May 30, 2006 at 13:38 UTC | |
Re: seek and process from there on
by davorg (Chancellor) on May 30, 2006 at 14:07 UTC | |
Re: seek and process from there on
by holli (Abbot) on May 30, 2006 at 13:58 UTC | |
Re: seek and process from there on
by Zaxo (Archbishop) on May 30, 2006 at 14:15 UTC | |
by Anonymous Monk on May 30, 2006 at 14:57 UTC | |
by qazwart (Scribe) on May 30, 2006 at 15:47 UTC | |
by blazar (Canon) on May 30, 2006 at 15:30 UTC | |
Re: seek and process from there on
by rminner (Chaplain) on May 30, 2006 at 13:52 UTC | |
by blazar (Canon) on May 30, 2006 at 14:06 UTC | |
Re: seek and process from there on
by Tobin Cataldo (Monk) on May 30, 2006 at 13:37 UTC | |
by blazar (Canon) on May 30, 2006 at 13:47 UTC | |
Re: seek and process from there on
by zakame (Pilgrim) on May 30, 2006 at 15:56 UTC | |
Re: seek and process from there on
by leocharre (Priest) on May 30, 2006 at 16:02 UTC |
Back to
Seekers of Perl Wisdom