ginju75 has asked for the wisdom of the Perl Monks concerning the following question:
hello wise Monks,
I am trying to read lines from a file which looks like this:
Description:
yada
yada
yada
yada
Data:
yada
yada
yada
yada
I need to put the lines between "Description:" and "Data:" in one Array and the lines after "Data:" and before EOF into a Second Array.
I use regular expressions to do this, but this does not seem to be efficient enough since I have to read the file into a string and then split it up as in...
open(R, filename); while(<R>) { $temp .= $_; } close(R); if($temp =~ /Description:(.*)Data:(.*)/s) { $result1 = $1; push (@array1, $result1); $result2 = $2; push (@array2, $result2); }
Instead I want to parse the file line by line and try to put the lines from the file into the arrays without first reading the whole file into a scalar...
Like maybe using some flags (someone suggested), but how?
Please not that the file will be of the format as mentioned above, but new tags maybe added, then the number of arrays to put the lines... will increase....
Thank you all for time and help...
A learning Monk...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to read lines from a file which is....
by Juerd (Abbot) on Jan 04, 2002 at 02:53 UTC | |
by jarich (Curate) on Jan 04, 2002 at 13:11 UTC | |
by Beatnik (Parson) on Jan 04, 2002 at 04:23 UTC | |
|
Re: How to read lines from a file which is....
by dvergin (Monsignor) on Jan 04, 2002 at 04:55 UTC | |
by rbc (Curate) on Jan 04, 2002 at 05:04 UTC | |
|
Re: How to read lines from a file which is....
by Anonymous Monk on Jan 04, 2002 at 03:50 UTC | |
|
Re: How to read lines from a file which is....
by dmmiller2k (Chaplain) on Jan 04, 2002 at 03:45 UTC | |
|
Re: How to read lines from a file which is....
by belg4mit (Prior) on Jan 04, 2002 at 05:05 UTC | |
|
Re: How to read lines from a file which is....
by seattlejohn (Deacon) on Jan 04, 2002 at 11:08 UTC |