Sign in with
Sign up | Sign in
Your question

Compare each char in multiple files in perl

Last response: in Applications
Share
April 11, 2011 3:46:03 AM

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.
a b L Programming
April 11, 2011 8:41:52 AM

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.
m
0
l
!