in reply to Programmatic regex disjunction

This should work:
use re "eval"; my @pats = ( qr/one/, qr/two/, qr/three/ ); my $joined = "(??{" . join("})|(??{", map "\$pats[$_]", 0..$#pats) . " +})"; my $any = qr/$joined/;

Replies are listed 'Best First'.
Re^2: Programmatic regex disjunction
by Aristotle (Chancellor) on Nov 22, 2005 at 09:01 UTC

    I really loathe the “join with right+left delimiter” idiom for paired delimiters. Since you don’t need a map for this, let me demonstrate that extreme to show why I don’t like it:

    my $joined = "(??{ \$pats[" . join( "] })|(??{ \$pats[", 0 .. $#pats ) + . "] })";

    Uhm, oh dear.

    Instead, I’d always prefer a map to put the delimiters in place before joining – it’s clearer, with less repetition of literals to boot. You’ve recognised the need for a map to clarify anyway – so take it to conclusion:

    my $joined = join '|', map "(??{ \$pats[$_] })", 0 .. $#pats;

    I think that looks a lot friendlier (than your code; to say nothing of my demonstration of atrocity).

    Makeshifts last the longest.