I like asiufy's idea and I'll definatly look into XML::Parser's subs style in the future. I don't think this is really the best way to go as I don't know the names of the tags that I'm looking for until runtime. On my test data file there are around 350,000 making me wonder if firing a start tag, end tag, etc handler a good idea.
For the same reasons, I was a bit scared off mirod's idea, there is anywhere between 10 and 30 columns I'm looking for so going through the data file and adding the CDATA sections seems a bit inefficient. I will bear this idea in mind, I'm tempted to try and change the data files to use these.
The best I can come up with is a single loop:
while (/<([^>]+)>/g) {
if ($1 eq '/r') {
print Dumper(\%temp);
undef %temp;
} else {
next unless $wanted{$1};
if (substr($1, 0, 1) eq '/') {
my $text = substr($_,$pos,pos()-$pos-length($1)-2);
$temp{substr($1, 1)} = $text;
} else {
$pos = pos();
}
}
}
gav^
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.