Regexp::Assemble would not track the original pattern correctly. I give up, it's too hard for me :(
use Regexp::Assemble; my $patterns = "/path/to/file.txt"; my $list_regex = Regexp::Assemble->new(file => $patterns); $list_regex->track( 1 ); open( FILE, "<", "$arg1") or die "$arg1: $!\n"; while (<FILE>) { if (/$list_regex/) {print "\n$arg1\n$list_regex->matched\n";} } close(FILE); }
Now I have this code but I'm facing a new problem. In my first example I use both flags /is I need /s so . to match newlines as well. I have this
my $patterns = "/path/to/file.txt"; my $arg1 = shift; open( PATTERNS, "<", $patterns ) or die "$patterns: $!\n"; my @list_patterns = <PATTERNS>; close PATTERNS; chomp @list_patterns; my $regexStr = "(" . join("|", @list_patterns) . ")"; my $list_regex = qr{$regexStr}i; open( FILE, "<", "$arg1") or die "$arg1: $!\n"; while (<FILE>) { if (/$list_regex/) {print "\n$arg1\n$1\n";} } close(FILE);

Adding s to both
my $list_regex = qr{$regexStr}is; or
if (/$list_regex/is)
would not solve the problem.
part1.*part2
This pattern working with my original script. .* should match also newline.
fggffgfg part1 hghggh ghhggh hggh part2 ytyty
This is the last problem, else the script working perfectly and much faster thanks to your advices. I will next take a look at local $/.

In reply to Re^3: Comparing pattern by mrc
in thread Comparing pattern by mrc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.