1.11M Members

matching and replacing characters of 2 files

 
0
 

I have 2 file
File1
1. amayaM
2. vismayaM
3. vismayaN
File2
1. amayamAn
2. vismayamAn
3. vismayamer

I need to check each character by character between 2 files and if the nonmatching character in first file is M then print the word in first file else no output.

output
1. amayaM
2. vismayaM

 
0
 

Hi laksraju,

Please could you show what you have done so far. The area of the code where you are having problems. Writing the code for you would not help you in the long run.

Secondly,you might look into the archieve of this forum. This kind of problem has been solved again and again. You can adapt one of the solved problems for your usage. And if you are still having problems, then come back we will be able to help.

thanks,
2teez

 
0
 

the code was done like this

use warnings;
use strict;

open my $fh1, '<', 'first_file.txt'  or die $!;
open my $fh2, '<', 'second_file.txt' or die $!;

while ( my $s1 = <$fh1> ) {
    chomp $s1;
    chomp( my $s2 = <$fh2> );

    ( $s1 ^ $s2 ) =~ /[^\x00]/;
    substr( $s2, $-[0], 0 ) ='M' if defined $-[0];
    print $s2, "\n";

}

close $fh2;
close $fh1;
 
0
 

Hi laksraju,

You apprently, didn't understand the solution to a similar question, you posted on Perlmonks and the solution given to you by Kenosis.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article