Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have a data file as shown below:-
Line nos added for reference..
1 Main 2 Name = Countries 3 End 4 5 Sub 6 Action = Find: NA 7 Text = North America 8 End 9 10 Sub 11 Action = Find: EU 12 Text = Europe 13 End 14 15 Main 16 Name = NA 17 End 18 19 Sub 20 Action = Find: US 21 Text = United States 22 End 23 24 Sub 25 Action = Find: CA 26 Text = Canada 27 End 28 29 Sub 30 Action = Find: MX 31 Text = Mexico 32 End 33 34 Main 35 Name = US 36 End 37 38 Sub 39 Action = 40 Text = Boston 41 End 42 43 Sub 44 Action = 45 Text = Atlanta 46 End 47 48 Main 49 Name = EU 50 End 51 52 Sub 53 Action = 54 Text = France 55 End 56 57 Sub 58 Action = 59 Text = Italy 60 End
I want to open the file, read the contents between first Main and the next (line nos 1 thru 14), and store in some data structure.
Then, I want to go back to the start and search for, say, Name = NA, go to that line (16) and read till I find the next Main (line 34).
I can use while <> to read one line at a time, but I am not sure how to go to a line upon a pattern match (in this case, match is "Name = NA" or "Name = US" , etc...) and then read the subsequent lines until I reach next 'Main'.
Please help
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading selected portion of a data file
by graff (Chancellor) on Jul 10, 2006 at 12:41 UTC | |
by Anonymous Monk on Jul 10, 2006 at 12:57 UTC | |
by graff (Chancellor) on Jul 10, 2006 at 13:15 UTC | |
by ww (Archbishop) on Jul 10, 2006 at 13:28 UTC | |
by Anonymous Monk on Jul 11, 2006 at 04:24 UTC |