http://www.perlmonks.org?node_id=246975


in reply to Zipcode Proximity script

If your C code is slow, a perl implementation will be even slower. What you need is a better data structure so you don't have to do a linear search over all codes, for example a quad tree. The module Tree::M might help.

Update: I notice that your perl code uses a flat-geometric distance rather than a curved-earth great circle distance. That's probably good enough for typical geometric queries (like "50 miles from my house"). But you could do the same thing in the C program. You could also search using the distance squared and avoid all those square roots.

my $xdelta = $x1-$x2; my $ydelta = $y1-$y2; my $distance_squared = $xdelta*$xdelta + $ydelta*$ydelta;

Replies are listed 'Best First'.
Re: Zipcode Proximity script
by hacker (Priest) on Mar 31, 2003 at 16:25 UTC
    It gets better than that. The reason I need them in CSV format in two columns of origin,destination like that, is because I have to import them into... wait for it... a Microsoft Access .mdb file, so an ASP page can query it. The import only happens rarely, but often enough to want to optimize the tool that is doing the conversion.

    I'm slowly converting the system (carbon-based and silicon-based) to perl/mysql/php, depending on the needs, but for now, it has to remain in ADO/.mdb format during the transition.

    I'll take a peek at Tree::M though and see what that can do for me. Thanks.