perl - How to match between two files -
i wrote perl script match specific words in 1 file , find lines contains them in second file. doesn't match relevant in first file , not picking of them in second file either. think there must thing wrong in code. can explain, please. thanks.
open $file2, '<', $f2; while (my $line_comp = <$file2>) { chomp $line_comp; $line_comp =~ m/(.*)(-from)(\s+)(\s*)(.*)(-scheme)(\s+)(\s*)(.*)(-to)(\s+)(\s*)(.*)/; $fr = $4; $sc = $8; $t = $12; if (defined $fr && defined $t){ open $file3, '+<', $f3; open $file4, '+>', $f4; while (my $line_write = <$file3>) { if ($line_write =~ m/(.*)(-)(\s*)scheme(\s+)($sc)(.*?)(-)(\s*)from(\s+)($fr)(.*?)(-to)(\s+)($t)(.*?)/sm){ print "$line_write\n"; } else { print $file4 "$line_write";} } copy ("$f4", "$f3") or die "copy failed: $!";
Comments
Post a Comment