Compare each char in multiple files in perl

kri_ari

Distinguished
Apr 10, 2011
1
0
18,510
Hello,

I have two files as shown below:

File1:

MANLGYWLLALFVAtWTDVGLCKKRPKPGGWNTGGSRYPGQGSPGGNRY
PPQGGGTWGQPHGGGWGQPHGGGWGQPHGGGWGQPHGGGWGQGGGTHNQ
WNKPSKPKTNMKHvAGAAAAGAVVGGLGGYMLGSAMSRPMIHFGNDWED
RYYRENMYRYPNQVYYRPVDQYsNQNNFVHDCVNITIKQHTVTTTTKGE
NFTETDVKMMERVVEQMCVTQYQKESQAYYDGRRSSAVLFSSPPVILLI
SFLIFLIVG

File2:


MANLGYWLLALFVTMWTDVGLCKKRPKPGGWNTGGSRYPGQGSPGGNRY
PPQGGTWGQPHGGGWGQPHGGSWGQPHGGSWGQPHGGGWGQGGGTHNQW
NKPSKPKTNLKHVAGAAAAGAVVGGLGGYMLGSAMSRPMIHFGNDWEDR
YYRENMYRYPNQVYYRPVDQYSNQNNFVHDCVNITIKQHTVTTTTKGEN
FTETDVKMMERVVEQMCVTQYQKESQAYYDGRRSSSTVLFSSPPVILLI
SFLIFLIVG

Need to compare each character of File1 with File2 and show the matching characters in an output.

Could any one help me for this??

Thanks,
Krish.
 

Rusting In Peace

Distinguished
Jul 2, 2009
312
0
19,060
So I'm not going to post code here because you'll not learn anything.

You need to do the following:

1) Read each file into an array. Perhaps you want to look here

2) Figure out which array is smaller and use that size as the loop size. If they are the same then just use the size.

3) Create a variable to store the matching characters.

4) In a for loop, iterate over both arrays by using the loop count to index into the array. Compare the array elements and if they are the same then add to the variable from step 3.

5) Do what ever you need to do to show the matching characters i.e. show them on screen.