sub latlong_cleanup # position comes in; has two parts, lat & long, separated by a comma with trailing stuff, degree symbols, etc. { chomp ($_[0]); #position has trailing cr/lf $_[0] =~ s/\ W\ /\-/; # West longitudes are negative $_[0] =~ s/\ E\ /\ /; # East longitudes are positive $_[0] =~ s/N//; # North latitudes are positive $_[0] =~ s/S\ /\-/; # South latitudes are negative $_[0] =~ s/\'//g; # both lat and longs have trailing strophe. remove it. $_[0] =~ s/\xB0/\./g; # replace degree character with decimal point (ASCII °) # converts lat/long from deg:mm:ss to decimals my $minutes; my ($lat, $long) = split(/,/, $_[0]); # split the position into lat/long $minutes = ($lat - int($lat)) /0.60; # "decimal-ize" the minutes $minutes = sprintf("%.2f", $minutes); # only need 2 digits; displays are not that good $lat = int($lat) + $minutes; # put it back together $minutes = ($long - int($long) /0.60); # "decimal-ize" the minutes $minutes = sprintf("%.2f", $minutes); # only need 2 digits; displays are not that good $long = int($long) + $minutes; # put it back together #join the lat/long back to $position; it came in as one field in an array, it probably # should go back that way $_[0] = join(',', $lat,$long); };