in reply to Re: Re: Re: Re: qr// with /e?
in thread qr// with /e?
Non-capturing parens ((?:...)) and flags ((?x-sim:...)) are used only in the parsing/compilation of the regular expression - they don't contribute nodes of their own to the resulting regexp program, but they may change what nodes something else compiles to.
For example, qr{.} gives the node 'SANY', while qr{.}s gives 'REG_ANY'.
However the compiler cannot stitch together subpatterns in compiled form, so whenever you build up a pattern from two previously qr'd patterns, or a qr'd pattern and some new text, perl constructs the stringified form of the new pattern and then compiles this new string from scratch.
Because of this, it is usually simpler for this sort of code to construct the string representing the complete pattern (with the added benefit that your diagnostics become more readable), so I'd tend to use:
rather than putting an additional qr{} in the map.my @days = qw( Sun Mon Tue Wed Thu Fri Sat ); my $days_re = join '|', map "\Q$_\E", @days; $days_re = qr{$days_re};
Hugo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: qr// with /e?
by tkil (Monk) on Apr 26, 2004 at 04:40 UTC | |
by hv (Prior) on Apr 26, 2004 at 09:14 UTC |