granted that is not what you asked... but it's much easier and more straightforward if you didn't already know about it.$re = qr/$regex/; $_ =~ $re;
Update actually since 5.005 it seems
Update2 I tried this...
...and got this...use Benchmark; sub make_grep { my $p = $_[0]; eval "sub { grep /$p/o, @_ }"; } sub make_grep2 { my $p = $_[0]; sub { grep /$p/o, @_ }; } $re = '(ob|[tTs])'; $a = make_grep($re); $b = make_grep2($re); $pat = qr/$re/; timethese(100000, { a => sub { $a->(qw(this is a test bob and jobe)) }, b => sub { $b->(qw(this is a test bob and jobe)) }, c => sub { grep $pat, qw(this is a test bob and jobe) } });
putting the compiled re to be much faster... maybe I did something wrong...Benchmark: timing 100000 iterations of a, b, c... a: 7 wallclock secs ( 5.92 usr + 0.00 sys = 5.92 CPU) @ 16 +891.89/s ( n=100000) b: 5 wallclock secs ( 4.57 usr + 0.00 sys = 4.57 CPU) @ 21 +881.84/s ( n=100000) c: 0 wallclock secs ( 0.62 usr + 0.00 sys = 0.62 CPU) @ 16 +1290.32/s (n=100000)
- Ant
In reply to Re: coderef assignment with and without eval
by suaveant
in thread coderef assignment with and without eval
by sacked
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |