in reply to fastest way to compare numerical strings?

You may get a very substantial improvement by only checking the longitudes if the latitudes are close. You can do this easily by splitting your if into two.

This runs in around 6 seconds here!

my @lat = map { rand( 180 ) - 90 } 1 .. 300_000; my @long = map { rand( 180 ) - 90 } 1 .. @lat; for my $lat ( 0 .. $#lat - 1 ) { if ( abs( $lat[$lat] - $lat[$lat+1] ) < 0.01 ) { for my $long ( 0 .. $#long - 1 ) { if ( abs( $long[$long] - $long[$long+1] ) < 0.01 ) { print "\$lat[$lat] = $lat[$lat] \$long[$long] = $long[ +$long]\n"; } } } }

Depending the spread of your points, this may give a very worthwhile improvement. But, if your points are all fairly close anyway, it won't be worthwhile.


Unless I state otherwise, all my code runs with strict and warnings

Replies are listed 'Best First'.
Re^2: fastest way to compare numerical strings?
by pc88mxer (Vicar) on Jun 30, 2008 at 23:56 UTC
    Unfortunately this does not solve exactly the same problem because you are only checking to see if $lat[$i] and $lat[$i+1] are close. The OP wants to find all $i and $j where $lat[$i] is close to $lat[$j].

    You can get closer to what the OP wanted if you first sorted the points based on $lat[...]. However, you still would want to check if $lat[$i+2], $lat[$i+3], etc. were close to $lat[$i].