in reply to Programmatic regex disjunction

Would you consider using the any function in Quantum::Superpositions ?

I have not used that in this context, but it may do what you need.

     "Man cannot live by bread alone...
         He'd better have some goat cheese and wine to go with it!"

Replies are listed 'Best First'.
Re^2: Programmatic regex disjunction
by gaal (Parson) on Nov 22, 2005 at 07:17 UTC
    Probably not in Perl 5. But with Pugs I already can, and would.

    my @pats = /one/, /two/, /three/; say "matched" if $string ~~ any @pats;

    Then again, Perl 6 Rules have better composition, uh, rules, so there's likely a way to do it without a junction. One reason to insist is that where

    $string ~~ any @pats

    matches,

    my $any = any @pats; $string ~~ $any;

    does not. This means that I can't use a junction and a precompiled disjunctive pattern interchangably e.g. in a given block:

    given $string { when $any { ... } # won't work if $any is a junction }

    At least, that's how it operates now; I'd better ask on p6-l if that's the desired behavior. :-)

    Update: come to think of it, it's almost certainly a pugsbug.