Perl6 Is it possible to use transitions in a mapping?

Can I use a join to match any of the values ​​in the join? I want to match any of the values ​​in an array. What is the right way to do this?

lisprog$ perl6 To exit type 'exit' or '^D' > my @a=<ab c> [abc] > any(@a) any(a, b, c) > my $x=any(@a) any(a, b, c) > my $y = "a 1" a 1 > say $y ~~ m/ $x / False > say $y ~~ m/ "$x" / False > my $x = any(@a).Str any("a", "b", "c") > say $y ~~ m/ $x / False > say $y ~~ m/ || $x / False > say $y ~~ m/ || @a / 「a」 > 

Thanks!

+5
source share
1 answer

Transitions are not intended to be interpolated into regular expressions. They are intended for use in regular Perl 6 expressions, especially with comparison operators (e.g. eq ):

 my @a = <xy z>; say "y" eq any(@a); # any(False, True, False) say so "y" eq any(@a); # True 

To match any of the array values ​​in the regular expression, simply write the name of the array variable (starting with @ ) in the regular expression. By default, this is interpreted as interleaving | ("the longest match"), but you can also indicate that it is an alternation || ("first match"):

 my @a = <foo bar barkeep>; say "barkeeper" ~~ / @a /; # 「barkeep」 say "barkeeper" ~~ / || @a /; # 「bar」 
+8
source

Source: https://habr.com/ru/post/1262261/


All Articles