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...
In reply to How to read lines from a file which is.... by ginju75
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |