Ok now is much clear, if your last post were the first one you would got more chance to get better replies.

Anyway I have some sparse hints you can try to speed up your code. First you are doing something like for 5 regex, for 50k lines that is very heavy approach: you are processing every line 5 times. Normally when you iterate over a file (with the slowness of filesystem) is better to do the opposite: for 50k lines, for 5 regex (even if the result of 5 * 50k and 50k * 5 is identic) and you do not really need the big array at all!

You are populating the array with a big amount of lines. This consume memory and slow your program. See reading large file where is explained that foreach my $line (<$readHandle>) {.. is list context and while (defined( my $line= <$readHandle>)) { is scalar context.

So you need a change in the loop, like

while (defined( my $ln= <$readHandle>)) { ... }

After this i see you are using if .. if .. if .. are you sure this is your intention? or better if .. elsif.. elsif .. else.. you really want to match more than one case?

Finally to speed up the loop you can insert some exit (from the loop) condition earlier in the loop. If this is possible is always worth to do.

Also if you can anchor somehow your regexes this will speed up a lot the match in long lines.

You can find these thread also interesting:

Optimising large files processing
Recommendations for efficient data reduction/substitution application
Using indexing for faster lookup in large file

HtH

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re^7: Using regex with a variable by Discipulus
in thread Using regex with a variable by Praveen Dharmaraj

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.