There are different ways to do things. What I want to do are (A) match any patterns in a Set, and (B) match all patterns in a Set in any order. E.g., if a set is (1,2,3), then (A) is true if a string contains 1, or 2, or 3; (B) is true if a string contains 1 and 2 and 3 in any order.
A while back, smls answered a question using array: perl6 Is using junctions in matching possible? (Thanks smls); but this time I want to use Set, using .one and .all if possible because using Set significantly simplifies other parts of my program.
I am using the July version of Rakudo. Here is a transcript. Thanks !!!
To exit type 'exit' or '^D'
> my $a = < one two 3 >
(one two 3)
> do "two" ~~ $a.one
True
> so 4 ~~ $a.one
False
> so "zzzonezz" ~~ $a.one
False
> my $b = "one"
one
> so "zzonezz" ~~ m/ {$b} / # trying to interpolate into regex
True
> so "zzzonezz" ~~ m/ { $a.one } / # trying to interpolate into regex
True
> say "zzzonezz" ~~ m/ { $a.one } /
「」 # empty match is True ?????
> my $c = "zzzonezz" ~~ m/ { $a.one } /
「」 # why is the match empty and not "one"?
> so "zzonezz" ~~ m/ $b /
True
> my $c = "zzzonezz" ~~ m/ $a.one / # $b above is evaluated,
# how come this one isn't evaluated ??
# why either /{$b}/ or /$b/ works, but only /{$a.one}/ works and
# /$a.one/ doesn't ???
False
> so "xxonetwo3xx" ~~ m/ { $a.all } /
True
> so "xxone 3 twoxx" ~~ m/ { $a.all } / # seems to work
True
> so "xxone 3 twoxx" ~~ m/ $a.all /
False