in reply to how to comment the lines if found a match
#!/usr/bin/perl use strict; use warnings; my @file_a_array; my $newfile; my $file_a = <path to word file>; my $file_b = <path to lines of text>; open (FILE_A, "$file_a") or die "couldn't open the file!"; while (my $line = <FILE_A>) { chomp ($line); push (@file_a_array, $line); } close (FILE_A); open (FILE_B, "$file_b") or die "couldn't open the file!"; while (my $line = <FILE_B>) { chomp ($line); foreach my $word (@file_a_array) { if ($line =~ /$word/) { $newfile = $newfile . "# "; } } $newfile = $newfile . $line . "\n"; } close (FILE_B); open (FILE_B, ">$file_b") or die "couldn't open the file!"; print FILE_B $newfile; close (FILE_B); print "end\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to comment the lines if found a match
by matrixmadhan (Beadle) on Dec 06, 2008 at 14:15 UTC | |
by kavitha (Initiate) on Dec 08, 2008 at 23:44 UTC |