Filtering elements of an array with elements of another array in Perl 6

后端 未结 3 1167
渐次进展
渐次进展 2021-01-18 09:09

I want to filter elements of @array which begin with elements of @search:

my @array = \         


        
3条回答
  •  生来不讨喜
    2021-01-18 09:40

    my @array = "aaaaa" .. "fffff";
    my @search = "aaaa" .. "cccc";
    my $join = @search.join('|');
    my $rx = rx{ ^ <{$join}> };
    
    @array.grep( * ~~ $rx ).map( *.put )
    

    You need to create the join string separately of it will evaluate the array join for each match. But the basically gives you what you want without using EVAL.

提交回复
热议问题