Creating a connection from an array with string values ​​in Perl 6

Here is what I am trying to do. It should be very simple, but I can’t figure out how to do it right.

> my @search_keys = <bb cc dd> [bb cc dd] > my $search_junc = @search_keys.join('|') bb|cc|dd > "bb" eq $search_junc False 
+3
source share
1 answer
 my @search_keys = <bb cc dd>; say "bb" eq any(@search_keys); # any(True, False, False) say so "bb" eq any(@search_keys); # True 

Syntax | is just sugar for calling any() function. Just like & is syntactic sugar for the all() function. They return Junction s, which you can collapse, for example. so . Of course, if you are going to use it in a conditional expression, you do not need to collapse it yourself, the Bool condition will do this for you:

 say "found" if "bb" eq any(@search_keys); 

See also: https://docs.perl6.org/type/Junction

+8
source

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


All Articles