in reply to Regex strings, deg:mm:ss, and all that
The regular expression makes heavy use of greedy and non-greedy matches, so it may be a little difficult to verify that it works, but I'm pretty confident that it's accurate.my $re = qr/([NS]?)\s*(\d+)(?:\D*)(\d*).*?,\s*([EW]?)\s*(\d+)(?:\D*)(\ +d*)/; unless ($latlong =~ /$re/) { die "unable to parse position\n"; } my $lat = $2 + $3/60; my $long = $5 + $6/60; if ($1 eq 'S') { $lat = -$lat; } if ($4 eq 'W') { $long = -$long; } return sprintf("%.2f,%.2f", $lat, $long);
|
|---|