It would help us a lot if you provided some example input and some sample output too (what you want and what you actually get ).
Do you ids come in the same order in the two files? In whick case there is no need to read in the whole of the first file, but you can just compare the two files on a line by line basis.
I would guess that your main source of inefficiency comes from how you are doing your comparisons:
for my $ID1 (keys %bow1) { for my $ID2 (keys %bow2) { ...
This will iterate though every ID in the first hash and compare it with every id in the second hash! From the sounds of it you are only interested in comparing entries with matching IDs, so why not use a hash as it was intended and look up the appropriate ID?
Also I don't understand why you are storing the IDs twice (both as the key and as an entry in the value array ( $bow2{$ID2}[0] = $ID2; )
Lastly and very much OT, you should always check for success on filehandle operations:
open (my $fh2, '<', "$file2") || die "Failed to open $file2 for readin +g : $!"; ...do stuff... close $fh2 || die "Failed to close $file2 : $!";
In reply to Re: how to compare two hashes with perl?
by BioLion
in thread how to compare two hashes with perl?
by FluffyBunny
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |