You say that you "need /s so . to match newlines as well", and I assume this means that if your pattern list includes something like
foo.*?bar, you would want that to match either of the following examples (where I'll put parens around the intended match):
example 1: blah (foobar) blah
example 2: blah (foo
all sorts of content on
lots of lines
of data
bar) blah
In that case, you need to read the data file in slurp mode:
my $regex_string = join '|', @list_patterns;
open( FILE, "<", $arg1 ) or die "$arg1: $!";
$_ = do { local $/; <FILE> }; # temporarily set $/ = undef to slurp f
+ile
close FILE;
if ( /($regex_string)/is ) {
# got a match...
}
Regarding the placement of parens and regex qualifiers, you could do that in other ways, like:
my $list_regex = qr/($regex_string)/is;
...
if ( /$list_regex/ ) {
...
No difference, really, but when there's a choice, I like having the parens visible in the code near the place where I use $1, $2, etc.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.