~~David~~:

Others have already suggested ways to speed your search. I'm just going to throw in a technique I occasionally find useful when dealing with large files. Sometimes you can easily differentiate between different types of data in your file, and take a quick pass over the file, discarding the obviously uninteresting stuff, creating a much smaller extract that fits in memory. You can then process that extract. For example, suppose your file looked something like this:

This header section contains a bunch of left-justified lines that are all shorter than 60 characters. Only the headers and summary lines are interesting. Col1 Col2 Col3 Notes ---- ---- ---- ------------- 1 123 123 Foo bar baz 2 741 200 Barbaz Foobar 3 100 0 Boofar fazboo Total: 323 Next header section, etc.

So you could discard all unless they are left-justified and shorter than 60 characters or don't contain 'Total:'. You can then use the faster in-memory techniques to dig through the extract. Something like so:

my @extract; while (<$INF>) { # Ignore useless lines next if length($_) > 60; next unless /^(\w|\s*Total:)/; push @extract, $_; } # Now you can process @extract for the interesting stuff print @extract;

...roboticus

Time flies like an arrow ... fruit flies like a banana.

--Groucho Marx


In reply to Re: Searching Array To Hold RegEx Stack Is Order Dependant by roboticus
in thread Searching Array To Hold RegEx Stack Is Order Dependant by ~~David~~

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.