Yeah, I guess if XML::Simple must load the entire data structure into memory, I don't think it's quite what I'm looking for. It just takes too long.

Maybe an example might help. Suppose I have the following XML input file:

<?xml version="1.0"?> <library> <book> <title>Dreamcatcher</title> <author>Stephen King</author> <genre>Horror</genre> <pages>899</pages> <price>23.99</price> <rating>5</rating> <publication_date>11/27/2001</publication_date> </book> <book> <title>Mystic River</title> <author>Dennis Lehane</author> <genre>Thriller</genre> <pages>390</pages> <price>17.49</price> <rating>4</rating> <publication_date>07/22/2003</publication_date> </book> <book> <title>The Lord Of The Rings</title> <author>J. R. R. Tolkien</author> <genre>Fantasy</genre> <pages>3489</pages> <price>10.99</price> <rating>5</rating> <publication_date>10/12/2005</publication_date> </book> </library>

Suppose I only want to import books that were published after January 1, 2002. If I apply such a filter when I do my initial import, the result should look like this:

$VAR1 = { 'book' => [ { 'publication_date' => '07/22/2003', 'price' => '17.49', 'author' => 'Dennis Lehane', 'title' => 'Mystic River', 'rating' => '4', 'pages' => '390', 'genre' => 'Thriller' }, { 'publication_date' => '10/12/2005', 'price' => '10.99', 'author' => 'J. R. R. Tolkien', 'title' => 'The Lord Of The Rings', 'rating' => '5', 'pages' => '3489', 'genre' => 'Fantasy' } ] };

The import will completely ignore entries that don't meet the specified criteria (in this case, publication_date must be >= '1/1/2002'). Can DOM or SAX-based parsing do this?


In reply to Re^4: How do I create an array of hashes from an input text file? by MrSnrub
in thread How do I create an array of hashes from an input text file? by MrSnrub

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.