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

referring to the same problem i want output in a file ,how can i get it?
  • Comment on Re^4: partial matching of lines in perl

Replies are listed 'Best First'.
Re^5: partial matching of lines in perl
by hippo (Archbishop) on Jun 15, 2020 at 11:03 UTC
Re^5: partial matching of lines in perl
by Sidd@786 (Initiate) on Jun 15, 2020 at 10:41 UTC
    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.

        please tell me the problem occuring in this program,because it is giving nothing in the output file.Input file contents are same as told earlier.