As Holy Week comes to a crescendo, I'm making some small progress on the ol' Cruise Ship project. The head monk is little lazy however, and while this part of the script works ok, I'm wondering if there is a way to tighten this up a bit. It seems, well, simple (Which is not a bad thing).

I could not find any preexisting modules that work with deg:mm:ss the way I needed so building this wasn't too bad - the extra characters in the dataset threw me off a few times though. Is there a better way to put this regex together? Is there a lat/log module I could use? And the input is one field from an array; I separate position into latitude and longitude - how would I return those to an array field? That sounded like a bad idea, so I did not try it.

Anyway, the routine:

sub latlong_cleanup # position comes in; has two parts, lat & long, separated by a comma w +ith 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 poin +t (ASCII &#176) # converts lat/long from deg:mm:ss to decimals my $minutes; my ($lat, $long) = split(/,/, $_[0]); # split the position into la +t/long $minutes = ($lat - int($lat)) /0.60; # "decimal-ize" the minutes $minutes = sprintf("%.2f", $minutes); # only need 2 digits; displa +ys 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; displa +ys 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); };

Update: I'd like to thank everyone for their suggestions. The first draft of the Cruise Ship project is off and running. You can see a screen shot of the ships in the Caribbean (at night) at my blog.


In reply to 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.