Have a look at XML::Twig, especially the section "XML::Twig 101". That has code examples and should get you started on how to parse the XML file, select the elements to handle, and only print those that you want to the output.

As for parsing the date, here's one of several ways to do that, using the DateTime and DateTime::Format::Strptime modules.

use DateTime; use DateTime::Format::Strptime; my $strp = DateTime::Format::Strptime->new(on_error=>'croak', pattern => '%Y%m%d%H%M%S %z'); my $input = "20140623203000 -0400"; my $dt = $strp->parse_datetime($input); print $dt->iso8601, "\n"; print "Weekday: ", $dt->day_of_week, " (", $dt->day_name, ")\n";

Another thing to note: In your description you talk about line-based parsing, which is a dangerous thing with XML. Many, many applications that work with XML don't consider some or all whitespace, including newlines, to be significant. That means that you may suddenly find two tags that were previously on two lines to show up on the same line, or have a tag and its attributes split over several lines, etc. That's one of the reasons XML should always be parsed with a real XML parser. Fortunately, there are lots available, with lots of different interfaces to suit different applications and different coding styles.


In reply to Re: How can I keep or discard certain blocks of an XML file based on first line of block? by Anonymous Monk
in thread How can I keep or discard certain blocks of an XML file based on first line of block? by Anonymous Monk

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.