Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: hash to hash comparison on large files

by moritz (Cardinal)
on Apr 08, 2009 at 13:56 UTC ( [id://756339]=note: print w/replies, xml ) Need Help??


in reply to hash to hash comparison on large files

You're only iterating over hashes, not using the lookup features. If you do it properly, you'll increase the speed of the loop roughly by the number of elements in %hash2.
while(my ($key1,$value1)=each(%hash1)){ while(my ($key2,$value2)=each(%hash2)){ if($key1 eq $key2){ ... } }

Should be better (and faster!) written as

while(my ($key1,$value1)=each(%hash1)){ if (exists $hash2{$key} ) { my $value2 = $hash2{$key} ... } }

Also note that this code:

foreach(@allhits){ while(my $str=<FH1>){
exhausts the <FH1> iterator for the first value in @allhits, and does nothing for the subsequent values - probably not what you want.

Likewise I don't see how you ever get items into @file2. (Update: I should have looked more carefully)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://756339]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 22:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found