Perl Checking if a scalar contains one of the elements in an array

后端 未结 3 985
傲寒
傲寒 2021-01-25 04:49

I have an array

my @array = qw/FOO BAR BAZ/;

and a scalar read from a file containing data like



        
3条回答
  •  一向
    一向 (楼主)
    2021-01-25 05:53

    You can create a regex that matches all of the @array:

    my $regex = join '|', map quotemeta, @array;
    $string =~ $regex;
    

提交回复
热议问题