I have a Perl function as shown below, and it is taking a longer time to execute. (Note: This function is being called more than 10,000 times.)
After googling some, I found that If I can precompile a Perl regex then the execution time may decrease.
How can I modify a Perl regex so that it takes less time? Or is there a better solution?
sub some_func {
my $var1=shift;
my $var2=shift;
if (!($var1 =~ /^UTF-?8$/)) {
print "Do something important\n";
}
if ($var2 =~ /$some_global_string/i) {
print "Do something important\n";
}
}
E.g., $var2 can be
"character string with maximum 4096 character, Including html character as string"
and $some_global_string can be:
"string as $var2 but max length of 256 character"`