in reply to Reaped: Re^8: partial matching of lines in perl
in thread partial matching of lines in perl

referring to the previous scenario if my input file has texts along with numbers and special characters then how this partial mismatching is done.

file1 contents: 1. Ram/is/going/reg[30] 2. he/is/coming/reg[31] 3. + what/goes/on/reg[32] file2 contents: 1. is/coming/reg[31] 2. on/reg[32] 3. try/to +/do/reg[65] output file contents: Ram/is/going/reg[30]

Replies are listed 'Best First'.
Re^2: Reaped: Re^8: partial matching of lines in perl
by hippo (Archbishop) on Jun 16, 2020 at 13:28 UTC
Re^2: Reaped: Re^8: partial matching of lines in perl
by AnomalousMonk (Archbishop) on Jun 16, 2020 at 16:18 UTC
    ... special characters ...

    I'm not sure what this thread is anymore (if it even really exists), but the handling of regex metacharacters or "special" characters is covered in haukex's Building Regex Alternations Dynamically article which I originally referenced here. Please read and understand it. And what hippo posted.


    Give a man a fish:  <%-{-{-{-<

Re^2: Reaped: Re^8: partial matching of lines in perl
by Sidd@786 (Initiate) on Jun 17, 2020 at 02:15 UTC
    use strict; use warnings; my $file1 = \<<"END1"; he/is/man/reg[30] don't/you/reg[31] what/goes/on/reg[32] END1 my $file2 = \<<"END2"; /is/man/reg[30] on/reg[32] try/to/do/reg[65] END2 open(my $f3, ">", "C:/Users/Siddharth/Desktop/do.txt") or die "Can't open < input.txt: $!"; open my $h2, '<', $file2 or die "cannot open file2"; my @a2 = <$h2>; close $h2; chomp @a2; my $match = join '|', @a2; $match = qr/$match/; open my $h1, '<', $file1 or die "cannot open file1"; my @a1 = <$h1>; close $h1; my $fh = grep {$_ !~ $match} @a1; print $f3 $fh; #print grep {$_ !~ $match} @a1;
    A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.