in reply to Re^10: Common Perl Pitfalls
in thread Common Perl Pitfalls
Why go for the expensive solution? If your pattern grows, at what moment do you revisit your program, and chop off the r in qr?
It's not that I never use qr. Sometimes, there's a (sub)pattern that's more readable as qr than as q. And sometimes, one does want a first class regexp construct. But those are the exceptions.
Do note that using q building blocks to build your patterns gives you more flexibility than limiting yourself to just qr:
To write that as qr, you'd have to write something like:my $vowels = 'aeiou'; my $odds = '13579'; my $odd_or_vowel = '[$vowels$odds]';
which, while matching the same language, throws off the optimizer, and makes not only for a slower compilation, the match itself is slower.my $vowels = qr/[aeiou]/; my $odds = qr/[13579]/; my $odd_or_vowel = qr/$vowels|$odds/;
|
|---|