Detecting Valid Latitude and Longitude Pairs

  • + 0 comments

    Perl

    while(<>){
        if ($. == 1){
            next;
        }
        if( /\((?<LAT>[\-\+]?[1-9]\d?(?:\.\d+)?),\s(?<LON>[\-\+]?1?\d{0,2}(?:\.?\d+))\)/ ){
            my $LAT = $+{LAT};
            my $LON = $+{LON};
           ($LAT >= -90 && $LAT <= 90 && $LON >=-180 && $LON <=180) ? print "Valid\n" : print "Invalid\n";
        } else {
            print "Invalid\n";
        }
    }