5

I am trying to find a simple way to match any of a group of words. I have been using a for loop, but is there a simpler way?

my @a=<a b c d e f>;
my $x="a1234567";
say $x ~~ m/ @a.any /;

It returns False. Is there a way to make it work? Thanks.

lisprogtor
  • 5,677
  • 11
  • 17

1 Answers1

4
my @a = <a b c d e f>;
my $x = "a1234567";
say $x ~~ /@a/;

/@a/ is the same as /| @a/ which is longest alternation. For alternation you can use /|| @a/.

CIAvash
  • 716
  • 1
  • 6
  • 5
  • @lisprogtor, Click on the check mark to the left of an answer if you want to accept it as the solution to your question (after clicking on it, the checkmark will change to a green color). Clicking on the check mark indicates that you don't need anymore help, and it gives points to the person who answered the question. – 7stud Jan 07 '17 at 14:41
  • Ah, I see !!! Thanks for pointing this out to me ! I will go back to click check marks for people who answered my other questions. Thanks. – lisprogtor Jan 08 '17 at 07:30