Hello-

I have written the following script for parsing XML, and it works for small files. For larger files, however, it runs out of memory. I have inserted the Tie::File module, to no avail. Is there anything I could do to improve I/O? Thanks in advance.

#!/usr/bin/perl $[ = 1; # set array base to 1 print "Enter modifier (e.g ISIN), input file, output file, each separa +ted by a space\n"; $enter = <STDIN>; @fields = split(/ /,$enter, 99999); #save array of modif +iers my @input; use Tie::File; #use Tie:File to get + data from xml doc tie @input, 'Tie::File', $fields[2]; @all = join("", @input); #join all of the li +nes of input together in one string $all = "@all"; @stories = split(/<\?xml/, $all, 99999); #split up the strin +g by story, using the <?xml tag foreach (@stories) { $_ = $_; $match = $_ if m#$fields[1]#; #go through the sto +ries, matching a modifier push (@matches, $match) #if it matches, add + to a new array } open(STDOUT, ">$fields[3]"); #print that new arr +ay to a new file print "@matches";

In reply to Parsing Large XML by shravnk

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.