X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=perl%2FUSDB.pm;h=c12247a34503b2ce47e3d93dc0251e669726dda9;hb=87bf0dca6185026ccce6d59612d913847134bdcc;hp=89cd9fe5661c9e1988e6e4a2954f58fdf9a2d85f;hpb=8178d787d7cc8040fa8958197582bba5c80e6f59;p=spider.git diff --git a/perl/USDB.pm b/perl/USDB.pm index 89cd9fe5..c12247a3 100644 --- a/perl/USDB.pm +++ b/perl/USDB.pm @@ -95,7 +95,7 @@ sub load my %dbn; if (-e $dbfn ) { - syscopy($dbfn, "$dbfn.new") or return "cannot copy $dbfn -> $dbfn.new $!"; + copy($dbfn, "$dbfn.new") or return "cannot copy $dbfn -> $dbfn.new $!"; } tie %dbn, 'DB_File', "$dbfn.new", O_RDWR|O_CREAT, 0664, $a or return "cannot tie $dbfn.new $!"; @@ -103,10 +103,20 @@ sub load # now write away all the files for (@_) { my $fn = shift; - my $f = gzopen($fn, "r") or return "Cannot open $fn $!"; - my $l; - while ($f->gzreadline($l)) { - chomp $l; + my $if = gzopen($fn, "r") or return "Cannot open $fn $!"; + my $ofn = "$fn.upk"; + my $of = new IO::File "+>$ofn" or return "Cannot read $ofn $!"; + my ($l, $buf); + while ($l = $if->gzread($buf)) { + $of->write($buf, $l); + } + $if->gzclose; + $of->close; + $of = new IO::File "$ofn" or return "Cannot read $ofn $!"; + + while (<$of>) { + $l = $_; + $l =~ s/[\r\n]+$//; my ($call, $city, $state) = split /\|/, $l; # lookup the city @@ -122,7 +132,8 @@ sub load } $dbn{$call} = $ctyn; } - $f->gzclose; + $of->close; + unlink $ofn; } untie %dbn;