Consider a string, like a response header: HTTP/1.1 404 Not Found
.
I'm curious if you could use the combination of the smartmatch (~~
or double tilde) operator and regex to search for incomplete, or a subset, of matches.
my $head = q{HTTP/1.1 404 Not Found};
my @success = (200, 201);
my @failure = (404, 409);
# Array First
say q{Success} if @success ~~ $head;
say q{Fail} if @failure ~~ $head;
# Array Second
say q{Success} if $head ~~ @success ;
say q{Fail} if $head ~~ @failure ;
I know this could be done with some sort of looping, grep, or map; but I am checking into the possibilities of what the ~~
can and can't do.
The documentation is pretty descriptive and for the majority of lhs/rhs conditions seems to follow a return true for an [all in left side] == [all in right side] evaluation.
That said, if $head
is just the number (eg $head=q{200}
) it would match.
The expected result would be similar to:
my $head = q{HTTP/1.1 201 OK};
my @success = qw(200 201);
say q{Success} if grep{$head =~ /$_/ } @success;