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

... finding reverse of the same problem ... find partially mismatched lines.

There is again a lack of clarity. I would define the "reverse of the same problem" as "find all lines in file1 that do not match any string in file2 as a substring." But "find partially mismatched lines" can be taken IMHO to mean "find all lines in file1 in which some part does not match any string in file2." All lines in file1 have some part that does not match anything in file2, but I doubt this is what you really mean.

If I take the former of the two interpretations above as your intended requirement ("find all lines in file1 that do not match any string in file2 as a substring"), then the code provided by BillKSmith here can easily be adapted by changing the statement
    print grep { $_ =~ $match } @a1;
to
    print grep { $_ !~ $match } @a1;
(!~ vice =~). This change produces the output you seem to be specifying here.

Again, please see How do I post a question effectively?, How (Not) To Ask A Question and I know what I mean. Why don't you? for help with asking questions more clearly: Please help us to help you. (And please do try to take a look at Short, Self-Contained, Correct Example and How to ask better questions using Test::More and sample data.)


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

Replies are listed 'Best First'.
Re^4: partial matching of lines in perl
by Sidd@786 (Initiate) on Jun 15, 2020 at 10:13 UTC
    referring to the same problem i want output in a file ,how can i get it?
      Also we have to operate with only file locations in program,we are not supposed to write actual texts of file in program(referring to the same problem) and we have to also print the output in other file.
        ... operate with only file locations ... not ... texts of file in program ...

        Opening files for reading in the "normal" way (as opposed to the ramdisk-ish approach used for convenience in the example code) is straightforward and is well described in the open and perlopentut docs. Maybe also take a look at Files and I/O in perlintro.

        ... print the output in other file.

        This merely involves opening a write filehandle (see docs referred to above) inside the Perl script and print-ing to this filehandle rather than to STDOUT by default, or else redirecting standard output from the Perl script as a whole to a file via the OS command line (see your OS docs regarding I/O redirection).

        Update: Minor wording changes to (hopefully) enhance clarity.


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

        use strict; use warnings; my $file1 = 'C:/Users/Siddharth/Desktop/goodfile.txt'; my $file2 = 'C:/Users/Siddharth/Desktop/badfile.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 $f3,'<',"C:/Users/Siddharth/Desktop/do.txt" or die "$!"; open my $h1, '<', $file1 or die "cannot open file1"; my @a1 = <$h1>; close $h1; my $fh = grep {$_ !~ $match} @a1; print $f3 $fh;

        2020-06-21 Athanasius added code tags.