1,105,332 Community Members

matching and replacing characters of 2 files

Member Avatar
laksraju
Newbie Poster
2 posts since Jul 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
2teez
Posting Whiz in Training
221 posts since Apr 2012
Reputation Points: 40 [?]
Q&As Helped to Solve: 38 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
laksraju
Newbie Poster
2 posts since Jul 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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;
Member Avatar
2teez
Posting Whiz in Training
221 posts since Apr 2012
Reputation Points: 40 [?]
Q&As Helped to Solve: 38 [?]
Skill Endorsements: 0 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article