Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Regex strings, deg:mm:ss, and all that

by hipowls (Curate)
on Mar 23, 2008 at 01:30 UTC ( #675708=note: print w/replies, xml ) Need Help??

in reply to Regex strings, deg:mm:ss, and all that

I don't know if you realize it but you are modifying the input string so that

my $pos = latlong_cleanup($data); # now $pos eq $data

You can grab the data you want using a single regex. I don't know what format the data is but I'll assume
23°34'N 12°25'W

use strict; use warnings; use YAML; use utf8; # to cope with the degree symbol in my test data. my $data = "2334'N 1225'W"; print Dump latlong_cleanup($data); sub latlong_cleanup { my $input = shift; if ( my ( $degN, $minN, $NS, $degE, $minE, $EW ) = $input =~ /(\d+)\xB0(\d+)'([NS]) +(\d+)\xB0(\d+)'([EW])/ ) { my $lat = sprintf "%0.2f", ( $NS eq 'S' ? -1 : 1 ) * ( $degN + ( $minN / 60 ) ); my $long = sprintf "%0.2f", ( $EW eq 'W' ? -1 : 1 ) * ( $degE + ( $minE / 60 ) ); return [ $lat, $long ]; } die "Invalid data [$input]"; } __END__ --- - 23.57 - -12.42

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://675708]
[LanX]: ;p
[marto]: LanX I'd rather commit sudoku :P
[marto]: trench humour folks, feeling rough.
[marto]: there is never a night when they sleep all the way through, but last night was something else
[marto]: gave in at 3:45 ish and let Charlie watch videos about spitfires, the battle of Britain. He's plane crazy
[1nickt]: marto soothing!
[marto]: Hiromi makes an appearance, let's hope Jools doesn't ruin it by joining in on the old Joanna
[1nickt]: karlgoethebier What is the issue with the semic-colon after the ellipsis? It's documented as proper syntax ...;

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2017-11-18 18:51 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (277 votes). Check out past polls.