$rtncd = InitStatVars(); sub InitStatVars{ # this sub reads the lookup directory and returns a list of files present my $rtncd = 0; my @tmp01 = (); # get list of statute hash file # strip of ext and sort alphanumerically @tmp01 = sort map{ substr(File::Basename::basename($_),0,-4) } glob($$cfg{basedir}.$$cfg{statdir}."*.pag"); if(scalar @tmp01 == 0){ # if there are no stat files return error $rtncd = 2; $logstr = "$cnty;$procdte;$fname;$module;1;error;[0003]Unable to intialize statute hash tables". ";InitStatVars(); ; ; "; UpdtMetaLog($$cfg{logdir},$logfile,$logstr); }else{ unshift @tmp01, MINDATE; # recs before this date have no equiv file } /_exc$/ || push @statfilelst, $_ foreach (@tmp01); # load statute file names to list for (0..$#statfilelst){ #initialize file handle arrays $statute[$_] = undef; # one for each statute file $statexc[$_] = undef; } return $rtncd; } #end InitStatVars(); $fhidx = SetFileHandleIdx($event_dt); sub SetFileHandleIdx{ # this sub crosses the date index to the correct array index my $event_dt = shift; my $fhidx = $#statfilelst; # use most recent file as default if(IsDateOK($event_dt)){ # determine which stat file for (0..$#statfilelst){ $fhidx = $_ if($event_dt ge $statfilelst[$_]); } }else{ # if date is not valid use most current $fhidx = $#statfilelst; } return $fhidx; } #end SetFileHandleIdx(); $rtncd = OpenFileHandle($fhidx) unless(defined($statute[$fhidx])); sub OpenFileHandle{ # this sub loads the tied hash reference my $fhidx = shift; my $rtncd = 0; $statute[$fhidx] = {}; $rtncd = (tie(%{$statute[$fhidx]}, "SDBM_File", $$cfg{basedir}.$$cfg{statdir}.$statfilelst[$fhidx], O_RDONLY, 0666)) ? 0 : 2; if($rtncd == 2){ $statute[$fhidx] = undef; $logstr = "$cnty;$procdte;$fname;$module;1;error;[0201]Could not tie hash files ". "$statfilelst[$fhidx];OpenFileHandle(); ; ; "; UpdtMetaLog($$cfg{logdir},$logfile,$logstr); } unless($rtncd){ if(-e "$$cfg{basedir}$$cfg{statdir}$statfilelst[$fhidx]"."_exc.pag"){ $statexc[$fhidx] = {}; $rtncd = (tie(%{$statexc[$fhidx]}, "SDBM_File", $$cfg{basedir}.$$cfg{statdir}.$statfilelst[$fhidx].'_exc', O_RDONLY, 0666)) ? 0 : 2; } if($rtncd == 2){ $statexc[$fhidx] = undef; $logstr = "$cnty;$procdte;$fname;$module;1;error;[0201]Could not tie hash files ". "$statfilelst[$fhidx];OpenFileHandle(); ; ; "; UpdtMetaLog($$cfg{logdir},$logfile,$logstr); } } return $rtncd; } #end OpenFileHandle(); if(exists($statute[$fhidx]->{$testval})) { do things ...}