in reply to /o is dead, long live qr//!
The place where qr// is important is when looping over strings and patterns. If you do a benchmark of code like this:
The qr// version will be considerably faster because Perl knows the regexes are already compiled, whereas in the string version, we need to compile three regexes for every line of input.while (<>) { for my $p (qr/a+b/, qr/c+d/, qr/e+f/) { foo() if /$p/ } } # vs. while (<>) { for my $s ('a+b', 'c+d', 'e+f') { foo() if /$s/ } }
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: /o is dead, long live qr//!
by Abigail-II (Bishop) on Jun 26, 2003 at 00:32 UTC | |
by belg4mit (Prior) on Jun 26, 2003 at 01:02 UTC | |
by Abigail-II (Bishop) on Jun 26, 2003 at 01:25 UTC | |
by belg4mit (Prior) on Jun 26, 2003 at 01:31 UTC | |
by diotalevi (Canon) on Jun 26, 2003 at 04:00 UTC | |
|
Re: Re: /o is dead, long live qr//!
by diotalevi (Canon) on Jun 25, 2003 at 23:46 UTC |