in reply to Re^2: [RFC] Building Regex Alternations Dynamically (updated x2)
in thread Building Regex Alternations Dynamically

(The following is perhaps a bit OT to the main thread, or else already touched upon in an update. Oh, well...)

... I think that adding an extra (?:...) makes the generated regex look a little more complex than it needs to be ... those are just stylistic concerns ...

Please see Re: Recognizing 3 and 4 digit number and thereunder for a long discussion between myself and kcott on these "stylistic concerns." Personally, I still don't see the need for the extra explicit  (?:...) wrap step. The implicit wrap becomes explicit quick enough if you print the stringized Regexp object, and this feature of a Regexp object should be deeply understood from the moment one begins to use them.

... skip the intermediate string variable, like in Haarg's post here: my ($regex) = map {qr/$_/} join '|', map .... ... it's more robust ...

To continue the previous point, I feel it's important to get a regex into a Regexp form as quickly as possible: no dilly-dallying. Once objectified, it can be used atomically when composing more complex regex expressions:

my $rx = qr{ ... }xms; ... $string =~ m{ $rx* $rx+? $rx{3,4} }xms and do_something();
(Of course, this compositional capability is also addressed by the  (DEFINE) predicate of the  (?(condition)yes-pattern) conditional expression of Perl 5.10+.)

The only situation which I'm aware of in which this compositional atomicity breaks down is for something like

my ($n, $m) = (3, 4); ... $string =~ m{ $rx{$n,$m} }xms and do_something();
where  $rx{$n} $rx{$n,} $rx{$n,$m} are all taken as hash element accesses. This can be fixed simply by an explicit layer of non-capturing group wrapping (entirely necessary here!):
    (?:$rx){$n} (?:$rx){$n,} (?:$rx){$n,$m}


Give a man a fish:  <%-{-{-{-<