Hello,

First of all, sorry for providing insufficient information about my problem. I understand now, that I need to explain my problem clearly for me to get some help.

OK. Here goes..

I am trying to find a few strings (stored in array) from about 50,000 lines of code in a file. After finding, I'm doing some changes to the matched strings and writing it to another file. To accomplish this task, I'm assigning 5 regexes to five variables.

foreach my $ur (@strings_to_be_matched) { $reg1 = qr/\=/i; $reg2 = qr/\S+\=\S+/i; $reg3 = qr/extern.+\b$ur\b\s*/i; $reg4 = qr/;$/i; $reg5 = qr/.+\b$ur\b\s*/i; foreach my $line (@contents_of_file) { if(($ln =~ $reg3 and $ln =~ $reg4)){ <some code> } if(($ln =~ $reg5 and $ln=~ $reg4 and ($ln !~ $reg1 or $ln =~ $reg +2)) { <some code> } if(($ln =~ $reg3 and $ln !~ $reg4)){ <some code> } if(($ln =~ $reg5 and $ln !~ $reg4 and $ln !~ $reg1)) { <some code> } } }

I'm using "qr" to pre-compile my regexes, so that I can reduce the time taken. I feel $reg5 is causing the problem here. The if conditions which involve $reg5 take longer time to match.

if (($ln =~ $reg5 and $ln=~ $reg4 and ($ln !~ $reg1 or $ln =~ $reg2))) { <some code here...> } if (($ln =~ $reg5 and $ln !~ $reg4 and $ln !~ $reg1)) { <some code here...> }

Another point to be noted is that, there are a few lines in the file which have a length of about ~12000. These lines take 4 seconds each to be processed.I want to reduce the time taken as few seconds taken to process each line are adding up to ~30 minutes. This is not acceptable at all in my case.


In reply to Re^6: Using regex with a variable by Praveen Dharmaraj
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.