in reply to Providing regex using an array

First of all please fix your indentation, you seem to be mixing spaces and tabs.

This might look ok in your editor, but your tab-length is 8 while we use 4 here.

It's hard to tell what you are trying to achieve, my best guess is to check that all regexes in an array individually match.

the following debugger-demo is using the fact that grep returns a count in scalar context

> perl -de0 DB<134> @patterns = ("^abd", "ghi"); DB<135> $string = "abd__ghi__" DB<136> p @patterns == grep { $string =~ $_ } @patterns 1 DB<137> DB<137> $string = "abd__xhi__" DB<138> p @patterns == grep { $string =~ $_ } @patterns DB<139>

even easier if you use all from List::Util

DB<139> use List::Util qw/all/ DB<140> $string = "abd__ghi__" DB<141> p all { $string =~ $_ } @patterns 1 DB<142>

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Providing regex using an array
by dgrunwal (Initiate) on Sep 11, 2022 at 20:00 UTC
    Thank you! Best, Dave