in reply to Re: Perl & Regex
in thread Perl & Regex
Not always. There are some advantages to using qr. There are some disadvantages as well. 1) qr takes more memory than a string, which may matter if you have a lot of them. 2) in some cases, if you construct a large regex out of many small parts, qr is significantly slower than using strings - this is because in non-trivial interpolations, a qr-ed regex first gets stringified, which gives lots of extra parenthesis.
#!perl -w use Devel::Size 'size'; print size('Price: \$([0-9]+\.[0-9]+)'), "\n"; print size(qr/Price: \$([0-9]+\.[0-9]+)/), "\n"; __END__ 50 104
|
|---|