in reply to hash to hash comparison on large files

instead of
while(my ($key2,$value2)=each(%hash2)){ if($key1 eq $key2){
try
if(exists $hash2{$key1}){
you can reduce some time.

UPDATE
is it a typing mistake

open(FH,"file1.txt")or die "can not open file"; open(FH1,"file1.txt")or die "can not open file";
opening the same file twice?!

since

#push(@allhits,$key1);
so
foreach(@allhits){
will iterate over nothing!.

moreover you have to read file1 again to get first column of file1 to be written into file2, so better change(going by your method)

push(@file1,$list1[1]."#".$list1[2],$list1[4]);
to
push(@file1,$list1[1]."#".$list1[2],[$list1[4],$list1[0]]); and in my @val1=split("/",$value1); use my @val1=split("/",$value1->[0]); and in #push(@allhits,$key1); use push(@allhits,[$key1,$value1->[1]]);#(correction from 0 to 1) and in my($id,$location)=split("#",$_); use my($id,$location)=split("#",$_[0]); and in print "$_";. use print "@{$_}"; # to what you got to write.
(Untested)

I agree with moritz on

while(my $str=<FH1>){
so use seek to move file pointer to the beginning after while loop ends

Vivek
-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.

Replies are listed 'Best First'.
Re^2: hash to hash comparison on large files
by patric (Acolyte) on Apr 08, 2009 at 17:11 UTC
    sooo sorry...its file1 for FH file handle and file2 for FH1 file handle. i changed from original filename to the sample file names that i had given as example. thats y :)