Nice huck, but I'd just like to give you a tidbit...

$@ is an interesting variable. As soon as you go into an eval, you overwrite (clear) that var immediately. Worse, because of its nature, it could be set elsewhere even while you're in your eval call, rendering your use of it useless, or worse, confusing. For these reasons, base a warn or other activities on whether the eval caught a throw directly, not on $@ which could be set somewhere else, even far away, that's not related even remotely to your check:

use JSON; my $json = new JSON; my $unjson; my $statement_ok = eval { $unjson = $json->allow_nonref->decode($message); 1; }; if (! $statement_ok){ # $@ can be interpolated ;) warn "json decode error: $@\n"; } my $lat = $unjson->{"location"}{"lat"};

If eval catches an exception, the true (1;) will never be returned, rendering $statement_ok undef, allowing you act based on the result of the eval, not whether $@ is set or not. You could further it a bit (untested):

my $ok = eval { foo(); 1; }; if (! $ok){ if ($@ =~ /internal error/){ warn "foo() fsck'd up!\n"; } else { warn "foo() fsck'd up, with unexpected err: $@\n"; } }

Looking at Try::Tiny, it explains what I've said in detail. That module is a different approach to your excellent example.


In reply to Re^2: Using Google APIs for Lattitude by stevieb
in thread Using Google APIs for Lattitude by mattpower

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.