With all due respect to the monks who suggest that you use an XML parsing module here (I do agree with them in general), I'm afraid that approach won't work for the sample data you posted. I hope (for your sake) that you just made some copy/paste errors when you were trying to post.

When I tried using XML::Parser on it, I got failures on the entity references λ and — -- maybe a good DTD will solve this. (I just converted them to unicode numeric entities -- λ — respectively.)

But beyond that, your 15 lines of XML data is badly messed up in terms of tag layout, and cannot be parsed as XML. Here's a little one-liner that will reduce your data sample to just the tags, putting one tag per line:

perl -pe 's{(?<=>)[^<]*}{\n}g' your_file.xml
That just replaces 0 or more characters between a > and a following < with a line-feed. Look carefully at the output, and you'll see what a mess it is. One big issue is that it starts with <sec>, and there's additional XML content after the corresponding </sec> token.

UPDATE: To see what I'm talking about more clearly, pipe the output of that one-liner through grep, like this:

perl -pe 's{(?<=>)[^<]*}{\n}g' your_file.xml | grep sec

In reply to Re: file handling error by graff
in thread file handling error by satzbu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.