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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |