olecs has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, this is probably a rather trivial question, but it is driving me nuts, and I can not manage to get it to work.

I have a latitude in degrees minutes seconds, like this:
55°48'10.000
I need to convert this to decimal degrees and to do that I need the 3 values separated by respectively ° and ' put into 3 separate variables.
Could anyone enlighten me on how to accomplish that? I first thought I could just substitute the ° sign with ' and then split on ' - but I am not able to do anything with °.

rgds,
Ole C.

Update
Thanks a lot for the suggestions. I ended up using davorgs solution since that was exactly what I wanted to do, but I also learned a new one with the \xB0 in the split from thundergnat.

Replies are listed 'Best First'.
Re: How to substitute a degree sign
by davorg (Chancellor) on Feb 28, 2006 at 17:01 UTC

    I'd concentrate on extracting the numbers, rather than removing the symbols.

    #!/usr/bin/perl use strict; use warnings; $_ = "55°48'10.000"; my ($d, $m, $s) = /([\d\.]+)/g; my $degrees = $d + ($m/60) + ($s/3600); print $degrees, "\n";
    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: How to substitute a degree sign
by thundergnat (Deacon) on Feb 28, 2006 at 18:08 UTC
    use strict; use warnings; my $latitude = "55°48'10.000"; my ($degrees, $minutes, $seconds) = split /[\xB0']/, $latitude; print $_,"\n" for ($degrees, $minutes, $seconds);
Re: How to substitute a degree sign
by Anonymous Monk on Mar 01, 2006 at 00:28 UTC

    TIMTOWTDI.

    $lat =~ tr/0-9//cd; $lat =~ /^(..)(..)(..(?:[.].)?)$/; my ($deg, $min, $sec) = ($1, $2, int($3));