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 = "23°34'N 12°25'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


In reply to Re: Regex strings, deg:mm:ss, and all that by hipowls
in thread Regex strings, deg:mm:ss, and all that by mcoblentz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.