Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
my $response; until (defined $response){ eval{ $response = $geocoder->geocode(location => $place); if ($@){ "Couldn't get location : $place\n"; }else{ ($long, $lat) = @{ $response->{Point}{coordinates} }; } } }

Whoa. I just took a look at the broader picture, and this chunk of code seems highly suspect. First off, let me say that I'm completely unfamiliar with Geo::Coder::Google and the Google service(s) involved, but one should never let compete ignorance prevent one from offering advice.

The primary problem I see is that the  $@ eval error variable is being evaluated within the eval block!

The docs for  $@ say (emphases added):

$EVAL_ERROR
$@    The Perl syntax error message from the last "eval()" operator.
          If $@ is the null string, the last "eval()" parsed and executed
          correctly (although the operations you invoked may have failed
          in the normal fashion).
          ...

It may be that the  geocode() method throws an exception (dies) and traps that exception, thus setting  $@ to a meaningful value; again, I'm not familiar with this module. If this is not the case, the test of  $@ in a given loop may actually be testing the value set on the previous iteration of the  until loop; however, I don't know if  eval() clears  $@ to a non-error value at the start of its execution.

Either of these possibilities (or perhaps some other) may explain why you are still getting latitude and longitude coordinates for places that do not exist, at least insofar as Google is aware, which does not seem to be helpful behavior for your program and, yes, does seem to be a problem!

Perhaps see the discussion of Error Variables in perlvar, likewise eval.


In reply to Re^7: How to make Geo::Coder::Google run even if input location doesn't exist by AnomalousMonk
in thread How to make Geo::Coder::Google run even if input location doesn't exist by M15U

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found