I've been handed a file that is laid out thusly
begin_section
name=section_name
type=section_type
begin_item
name=item_name
desc=item_description
link=item_link
end_item
begin_item
.
.
.
end_item
end_section
begin_section
.
.
.
end_section
and so on and so on.
What would be a good way of reading this file into a data structure that I can use nicely?
I'd thought of setting up a couple of objects; a Section object, which would then contain a number of Item objects. And maybe an overall object to hold all the Section objects.
But I'm stalling at the file parsing stage. I don't seem to be able to do this kind of thing:
if(/begin_item/) {
while (!/end_item/) {
...deal with data members here...
}
}
Am I approaching this problem the wrong way?
Many thanks in advance for any advice you may have.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.