mao9856 has asked for the wisdom of the Perl Monks concerning the following question:
I have two huge files. File1 has one column and File2 has two columns as follows:
File1
ABCD12
XYZ13
EFGT45
UVWZ34
TSR78
........
File2
ID121 ABC14
ID122 EFG87
ID145 XYZ43
ID157 TSR11
ID181 ABC31
ID962 YTS27
ID529 EFG56
ID684 TSR07
ID921 BAMD80
.............
I want to match first column of File1 and starting three alphabets of second column of File2 and print Ids of those are matched.Desired output:
ID121 ABC14
ID122 EFG87
ID145 XYZ43
ID157 TSR11
ID181 ABC31
ID529 EFG56
ID684 TSR07
I tried foloowing code:
#!/usr/bin/perl use strict; use warnings; my ($f1,$f2,@patterns,%patts,$f2_rec,$f2_field); $f1 = $ARGV[0]; $f2 = $ARGV[1]; open(PATT,"<", $f1) or die; @patterns = <PATT>; chomp(@patterns); close(PATT) or die; @patts{@patterns} = (1) x @patterns; open(FILE,"<", $f2) or die; while (defined ($f2_rec = <FILE>)) { chomp $f2_rec; $f2_field = (split(/ /,$f2_rec))[0]; if(exists($patts{$f2_field})) { print "$f2_rec\n"; } } close(FILE) or die;
It know it won't separate matching initial three alphabets, but it will match exact values with 'error: use of unitialized value' until use warnings is blocked. Please help.
Back to
Seekers of Perl Wisdom