XP is just a number | |
PerlMonks |
Re^7: Using regex with a variableby AnomalousMonk (Archbishop) |
on Mar 15, 2016 at 16:41 UTC ( [id://1157826]=note: print w/replies, xml ) | Need Help?? |
Another trick to reduce processing time is to compose all the @strings_to_be_matched strings into a single regex. I'm making a couple of assumptions:
So your final code might look something like this (untested): (But please see Discipulus's remarks above about using a while-loop rather than a for-loop for processing file contents line-by-line.) Another thing that may affect speed is that you have all your regexes $reg1 $reg2 $reg3 $reg4 $reg5 modified as /i (case insensitive). Case insensitivity slows down regex execution. Some of your regexes have only assertions, characters or character classes \S $ ; = to which case insensitivity does not apply. As noted above, the @strings_to_be_matched strings seem to be C/C++ or suchlike keywords or identifiers; is case insensitivity ever appropriate here? I would seriously reconsider the use of case-insensitivity. Last but not least: As a beginner, it's important always to usewarnings; and usestrict; and avoid global variables. Give a man a fish: <%-{-{-{-<
In Section
Seekers of Perl Wisdom
|
|