=pod Code submission from: Paul Schaap (schaappa@ozemail.com.au) fastFind 1.0.0 Release Notes WHY === A very,very fast way to do a search on a very large file. Achieved by presorting the file and making the length of each field the same. You can then use the awesomely quick sysseek and sysread Perl functions. INSTALLATION ============ ï Install MacPerl 5.1.4r4 or greater.(Thanx Matthias) And add Chris Nandors Sort Perl Module on the Mac, or, use Alpha or Word to sort the Index file. USAGE ===== 1) Drop a file with the structure :- 1. Name 2. Address 3. Suburb 4. Postal Code 5. Phone number delimited by pipe "|" onto 'generateIndex Droplet' (e.g. generateIndex Input). 2) Open and run fastFind.pl then maybe use it as a require in an application or cgi. CHANGES ======= V1.0.0 ï Well none really, first cut. CHEERS schaapp@ozemail.com.au - I Only read email once a fortnight, sorry. =cut #!perl ###################################################################### ########## # PROGRAM : fastFind.pl # BY : Paul Schaap # DATED : 05/01/1998 # PURPOSE : Read Large files instantly ###################################################################### ########## # USAGE &fastFind(Index filename,Indexcount filename,key); print &fastFind("indexFile","indexCount","056736426"); # FASTFIND ROUTINE #================== sub fastFind { $table = $_[0]; $count = $_[1]; # Read Number of Rows and Table structure open(PC,$count) or print "Failed to open $count\n"; @indexInfo = split(/,/,); $indexRows = $indexInfo[0]; $keyLength = $indexInfo[1]; $value = sprintf("%$keyLength.$keyLength"."s",$_[2]); $rowLength = $indexInfo[1]; for($i=2;$i< @indexInfo;$i++){ $rowLength = $rowLength + $indexInfo[$i]; $fieldLength[$i] = $indexInfo[$i]; } close PC; $rowLength = $rowLength + 1; #print "$rowLength\n"; # Go for it open(PH,$table) or return "Cannot open $table\n"; $result = ""; $low = 0; $high = $indexRows - 1; while($low <= $high){ $mid = int (($low + $high) / 2); $off = $mid * $rowLength; #print "$mid $off\n"; sysseek PH,$off,0; sysread PH,$rec,($rowLength-1); $key = substr($rec,0,$keyLength); $result = substr($rec,$keyLength,$rowLength-$keyLength); #print "-$key-$rec-\n\n"; if($key eq $value){ close PH; return $result; } else { if($key gt $value){ $high = $mid - 1; } else { $low = $mid + 1; } } } close PH; return "NOT FOUND"; } 1; # END #####################################################################