When I am splitting the key to lat long, it gets split with the number, not the decimal part.

I'm not the best one to help with XML stuff, but I can perhaps offer help on this. I think the best approach is not to split away what you do not want, but to extract what you do want, real numbers in this case. The Regexp::Common module is useful in this, for it defines a real-number pattern.

Win8 Strawberry 5.30.3.1 (64) Tue 01/12/2021 14:15:24 C:\@Work\Perl\monks >perl -Mstrict -Mwarnings # pm#11126809 use Regexp::Common qw(number); my $rx_lat_lon = qr{ (?<! \d) $RE{num}{real} (?! \d) }xms; for my $lat_lon ( '123,456', '12.345, -0', ' -2. , 0.987', ' -.0 ,0.987 ', '0, -0', '.0 ,-.0', '0. , -0.', ' 0.0 , -0.0 ', '1, -1', '.1 ,-.1', '1. , -1.', ' 1.2 , -1.2 ', '123 456', '123', 'foo', '123,foo', 'foo,123', '1.234.5', ) { my $got_lat_lon = my ($lat, $lon) = $lat_lon =~ m{ \A \s* ($rx_lat_lon) \s* , \s* ($rx_lat_lon) \s* \z + }xms; # $lat_lon =~ m{ $rx_lat_lon }xmsg; # no data validation if ($got_lat_lon) { printf "%18s -> lat %-10s lon %-10s \n", "'$lat_lon'", n_or_undef($lat), n_or_undef($lon); } else { print "'$lat_lon' FAILED to extract lat/lon \n"; } } sub n_or_undef { return defined $_[0] ? "'$_[0]'" : 'undef'; } ^Z '123,456' -> lat '123' lon '456' '12.345, -0' -> lat '12.345' lon '-0' ' -2. , 0.987' -> lat '-2.' lon '0.987' ' -.0 ,0.987 ' -> lat '-.0' lon '0.987' '0, -0' -> lat '0' lon '-0' '.0 ,-.0' -> lat '.0' lon '-.0' '0. , -0.' -> lat '0.' lon '-0.' ' 0.0 , -0.0 ' -> lat '0.0' lon '-0.0' '1, -1' -> lat '1' lon '-1' '.1 ,-.1' -> lat '.1' lon '-.1' '1. , -1.' -> lat '1.' lon '-1.' ' 1.2 , -1.2 ' -> lat '1.2' lon '-1.2' '123 456' FAILED to extract lat/lon '123' FAILED to extract lat/lon 'foo' FAILED to extract lat/lon '123,foo' FAILED to extract lat/lon 'foo,123' FAILED to extract lat/lon '1.234.5' FAILED to extract lat/lon
(I haven't tested it, but I think this code will work under virtually any Perl version. (Update: Counter-examples are welcome!))

Some comments:


Give a man a fish:  <%-{-{-{-<


In reply to Re^9: Update XML Values using two primary keys by AnomalousMonk
in thread Update XML Values using two primary keys by pratikpooja

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.