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

$file1 = \<<"END1"; he/is/man/reg[30] what/goes/on/reg[32] i_am_a_man you_are_reg[60] END1 my $file2 = \<<"END2"; /is/man/reg[30] are_reg[60] try/to/do/reg[65] you/reg[31] END2 open(my $f3, ">", "C:/Users/Siddharth/Desktop/two.txt") or die "Can't open < input.txt: $!"; open my $h2, '<', $file2 or die "cannot open file2"; my %map = <$h2>; my ($regex) = map { qr/$_/ } # 2. join '|', map {quotemeta} close $h2; open my $h1, '<', $file1 or die "cannot open file1"; my @a1= <$h1>; #print grep {$_ =~ $regex} @a1; print $f3 grep {$_ !~ $regex} @a1;

Replies are listed 'Best First'.
Re^13: partial matching of lines in perl
by marto (Cardinal) on Jun 17, 2020 at 11:24 UTC

    You've been asked several times to make some effort when asking for help, dumping code without a description of what is happening is just lazy.

    Global symbol "$file1" requires explicit package name (did you forget +to declare "my $file1"?) at sid.pl line 5. Can't find string terminator "END1" anywhere before EOF at sid.pl line + 5.

    See previous notes on use strict; use warnings;.

    open(my $f3, ">", "C:/Users/Siddharth/Desktop/two.txt") or die "Can't open < input.txt: $!";

    two.txt and input.txt aren't the same file, your report is wrong as you report a reading failure when you're actually trying to write a file. Take the time to read and understand the responses and working examples you've already been given.

Re^13: partial matching of lines in perl
by choroba (Cardinal) on Jun 17, 2020 at 11:51 UTC
    Are you sure you want to map quotemeta to the return value of close?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re^13: partial matching of lines in perl
by Sidd@786 (Initiate) on Jun 17, 2020 at 11:50 UTC
    use strict; use warnings; my %ads_list_hash=(); my $file1 = \<<"END1"; he/is/man/reg[30] what/goes/on/reg[32] i_am_a_man you_are_reg[60] END1 my $file2 = \<<"END2"; /is/man/reg[30] are_reg[60] try/to/do/reg[65] you/reg[31] END2 open(my $f3, ">", "C:/Users/Siddharth/Desktop/two.txt") or die "Can't open < two.txt: $!"; open my $h2, '<', $file2 or die "cannot open file2"; my %map = <$h2>; my ($regex) = map { qr/$_/ } # 2. join '|', map {quotemeta} close $h2; open my $h1, '<', $file1 or die "cannot open file1"; my @a1= <$h1>; #print grep {$_ =~ $regex} @a1; print $f3 grep {$_ !~ $regex} @a1;
    A reply falls below the community's threshold of quality. You may see it by logging in.