in reply to Re: Debugging Help!!!
in thread Debugging Help!!!

Hi Monks!
This code is generating a error that I believe that it is occurring on the regular expression from the "sub parse_location", can someone take a look at it and let me know where this error "Use of uninitialized value in concatenation (.) or string" is coming from?
Here is the actual code.

#!/perl/bin/perl -w use strict; # convert a string which looks like "34:45:12N,15:34:10W" into a pair # of degrees. Also accepts "34.233N,90.134E" etc. my ($lat1,$long1) = parse_location('34:45:12N'); print "$lat1, $long1\n"; sub parse_location { my($str) = @_; print "$str\n"; my($lat,$long); if ($str =~ /^([0-9:.\260'"d -]*)([NS])[, ]+([0-9:.\260'"d -]*)([E +W])$/i) { return undef if (!defined($lat = &parse_degrees($1))); $lat *= (($2 eq "N" || $2 eq "n") ? 1.0 : -1.0); return undef if (!defined($long = &parse_degrees($3))); $long *= (($4 eq "E" || $4 eq "e") ? 1.0 : -1.0); return(&degrees_to_radians($lat), &degrees_to_radians($long)); + } else { return undef; } }

Thanks for the big Help!

20060413 Corion Reparented under Re: Debugging Help!!!, as it's a continuation of this thread

Replies are listed 'Best First'.
Re: Regular Expression Help!!
by japhy (Canon) on Apr 13, 2006 at 13:37 UTC
    You're only passing HALF of what's needed to the function. It's expecting latitude and longitude. You're only giving it latitude (or longitude, I can't remember which).

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
      Did you run it by adding another value?
        Well, you've kind of left out parse_degrees() and degrees_to_radians(), so I couldn't test it fully, but to answer your question, yes.
        my ($lat1,$long1) = parse_location('34:45:12N,12:34:56E');
        That "worked" for me.

        Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
        How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart