Working?
[spider.git] / perl / USDB.pm
index 4cd4143bd3b7aca6794a188678ba8d43a3f2b2cb..c12247a34503b2ce47e3d93dc0251e669726dda9 100644 (file)
@@ -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;