Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^7: How to make Geo::Coder::Google run even if input location doesn't exist

by AnomalousMonk (Canon)
on Mar 01, 2013 at 17:14 UTC ( #1021302=note: print w/replies, xml ) Need Help??

in reply to Re^6: How to make Geo::Coder::Google run even if input location doesn't exist
in thread How to make Geo::Coder::Google run even if input location doesn't exist

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):

$@    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.

Replies are listed 'Best First'.
Re^8: How to make Geo::Coder::Google run even if input location doesn't exist
by M15U (Acolyte) on Mar 04, 2013 at 17:08 UTC

    You are right, I forgot to put the print statement. Actually I'm pretty knew to perl so I have some problems wraping my mind around all the perl functions.

    As I understand by this point my script, when it encounters an unknown location it will not search for coordinates, instead it will take the previous detected coordinates and replace the ones in the unknown location.

    As you suggest, it doesn't really look as a good practice, but for know it works for me... Thank you for your advices nevertheless

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1021302]
Discipulus a missing semicolon after use LWP::UserAgent caused very strange behaviour and not the normal warning...
[choroba]: Yes, sometimes missing ; after the use clause just interprets the next line somehow and passes the result to the used module which could happily ignore it. Been there, seen that.
[Discipulus]: luckly the program was 20 lines!

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2017-02-28 08:49 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (398 votes). Check out past polls.