use strict; use warnings; #create the all the required stuff first my ($i,$vals,$score,$k,%d); #some counter variables and other things #now randomly select something from the list of hashes #thnx to ccn and tye and jdporter for helping me out in this @ref=\(%a,%b,%c); #a list of hashes stored as reference in an array $i=0; #now loop for lets say 10 iterations... since this is just a sample while($i!=10) { my $hashref = $ref[rand @ref]; #select a random hash from the list # this was jdporter's idea... thnx again #fill in the hash with some values.... #the values entered will be of the form (value,score) $vals=<>; $score=<>; $hashref->{$vals}=$score; } $i=0; #the hashes are filled.... ie my database is complete #now apply the FA to search the top-k data my(@keys1,@keys2,@keys3,@vals1,@vals2,$key1,$key2,$key3,$val1,$val2,$val3); while(1) #loop indefinitely { #parse each hash simultaneously @keys1=keys(%a),@keys2=keys(%b),@keys3=keys(%c); @vals1=values(%a),@vals2=values(%b); my($seen1,$seen2); foreach $key1(@keys1) { foreach $key2(@keys2) { if($key1==$key2) { d{$key1}=$vals1[$i++]; $seen1=1; } } foreach $key3(@keys3) { if($key1==$key3) { d{$key1}=$vals2[$i++]; $seen2=1; } } if($seen1==1 and $seen2==) { print "sort(keys(%d))\n"; die "your query was found\n"; } } }