in reply to Regex: Extracting the case insensitive string and printing on the output
Benchmark: timing 2222234 iterations of code_1, code_2... code_1: 4 wallclock secs ( 4.03 usr + 0.00 sys = 4.03 CPU) @ 55 +1422.83/s (n=2222234) code_2: 2 wallclock secs ( 2.27 usr + -0.01 sys = 2.26 CPU) @ 98 +3289.38/s (n=2222234) Rate code_1 code_2 code_1 551423/s -- -44% code_2 983289/s 78% --
$mytarget = "I am a perl program"; $mystring = "Perl"; if ($mytarget =~ m/\Q$mystring\E/i) { print "It matches: ${^MATCH}\n"; } else { print "It doesn't match\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex: Extracting the case insensitive string and printing on the output
by AnomalousMonk (Archbishop) on Nov 29, 2011 at 08:16 UTC |