in reply to Trapping errors

I am also not familiar with this module, but this does not seem to be quite right:
if ($loop < 10) { $geocoder = Geo::Coder::Google->new(apiver => 3); eval{ $latlong = $geocoder->geocode(location => $location); if ($1){ print "!!! !!! !!! --- Couldn't get location : $locati +on --- !!! !!! !!!\n"; }else{ $map_coords = $latlong->{geometry}{location}{lat} . " +" . $latlong->{geometry}{location}{lng}; print ( " job no.\: $job_count $job_title \=\=\> $department $ +location $map_coords \n" ); $loop++; } } }
Now the questions: 1. if ($1), $1 is a special variable used for the first successful match in a regex, but you don't seem to be using any regex. 2. Nor sure you should use an eval, it might be better to see if $latlong is defined and is a reference (I assume it should be a reference) to some data structure that is also properly defined. 3. If you really want to use eval, then you should really check the value of $@, which contains the Perl error message from the last eval (but AppleFritter++ has already mentioned this to you. In brief, you do not seem to be doing the steps needed to catch an error, I am not too surprised that you don't catch any.

Now, of course, all the above is in part speculation, as I said, I do not know this module (and have no time right now to go through it), but I still hope it might help you.

Replies are listed 'Best First'.
Re^2: Trapping errors
by mcoblentz (Scribe) on Jul 23, 2014 at 23:17 UTC
    Ah, thank you for all that. I went through the usual error variables and ultimately found that the API call was not returning an error per se - but in the internal 'status' field it says, "ZERO RESULTS". So I need to read the status field from the returned hash and control the program flow from there. Problem is, I am not certain how to read the hash. I didn't call for one so what do I read? Any thoughts? Thanks!
      Your $geocoder variable is probably a reference to an object that most probably has accessors within its methods. Use them. If worse comes to worse, you could probably use the Data::Dumper to figure out the underlying data structure, this might help you understanding what is going on, but you should most probably not rely on that for your real program, but use the methods provided by the interface.