Hi Monks!
I am working on this weather script and I am fetching 15 zip codes as an example of my issue. The issue is that every time I run the code I have random missing values, am I doing something wrong on the Perl side, is there a better way of doing this? Here is a code sample and you can see these random missing values on the "$city" variable if you ran this.
#!/usr/bin/perl -w use strict; use CGI qw(-oldstyle_urls :standard); use XML::TreePP; use XML::XPath; use XML::Simple; use Data::Dumper; use Date::Format; use Date::Parse; my $q = new CGI; $| = 1; my @zipcode = qw(02151 01908 02638 02669 02670 02536 02642 02574 02332 + 02601 02045 01930 02152 27943 02169); my ($currtempf, $currtempc, $currhumidity, $currcondition, $currwind, +$todayhigh, $todaylow, $todaycond, $tomorrowcond); my ($city, $url, $tpp, $tree); foreach my $zip(@zipcode) { next unless $zip =~ /^(\d{5})$/; $url = "http://www.google.com/ig/api?weather=".$zip ; $tpp = XML::TreePP->new(); $tree = $tpp->parsehttp( GET => $url ); $city = $tree->{xml_api_reply}->{weather}->{forecast_information}-> +{city}->{"-data"} || ''; $currtempf =$tree->{xml_api_reply}->{weather}->{current_conditions} +->{temp_f}->{"-data"} || ''; $currtempc =$tree->{xml_api_reply}->{weather}->{current_conditions} +->{temp_c}->{"-data"} || ''; $currhumidity =$tree->{xml_api_reply}->{weather}->{current_conditio +ns}->{humidity}->{"-data"} || ''; $currcondition =$tree->{xml_api_reply}->{weather}->{current_conditi +ons}->{condition}->{"-data"} || ''; $currwind =$tree->{xml_api_reply}->{weather}->{current_conditions}- +>{wind_condition}->{"-data"} || ''; $todayhigh =$tree->{xml_api_reply}->{weather}->{forecast_conditions +}->[0]->{high}->{"-data"} || ''; $todaylow =$tree->{xml_api_reply}->{weather}->{forecast_conditions} +->[0]->{low}->{"-data"} || ''; $todaycond =$tree->{xml_api_reply}->{weather}->{forecast_conditions +}->[0]->{condition}->{"-data"} || ''; $tomorrowcond =$tree->{xml_api_reply}->{weather}->{forecast_conditi +ons}->[1]->{condition}->{"-data"} || ''; print "**City=$city** - Url=**$url**\n"; }

Thanks for looking and the help!!!

In reply to Missing values when running code. by Anonymous Monk

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.