in reply to Problem Parsing XML with Perl

# my $weatherIconURL = $data->{'data'}->{'parameters'}->{'conditions-i +con'}->{'icon-link'}->[0]; my $weatherIconURL = $data->{'data'}->{'parameters'}->{'conditions-ico +n'}->{'icon-link'}->[-1];

Replies are listed 'Best First'.
Re^2: Problem Parsing XML with Perl
by Perobl (Beadle) on Oct 25, 2009 at 15:01 UTC

    Thanks for the suggestion.

    It looks like the [-1] forces retrieval of an earlier URL. I tried this, but this morning the problem has vanished from NOAA's XML data so I can't verify whether or not this will solve the problem.

    I thought I could maybe do the following:

    if (exists $data->{'data'}->{'parameters'}->{'conditions-icon'}->{'ico +n-link'}->[0]) { $weatherIconURL = $data->{'data'}->{'parameters'}->{'condi +tions-icon'}->{'icon-link'}->[0]; print "Weather Icon: ", $data->{'data'}->{'parameters'}->{ +'conditions-icon'}->{'icon-link'}->[0], "\n"; } else { $weatherIconURL = $data->{'data'}->{'parameters'}->{'condi +tions-icon'}->{'icon-link'}->[-1]; print "Weather Icon: ", $data->{'data'}->{'parameters'}->{ +'conditions-icon'}->{'icon-link'}->[-1], "\n"; }

    Do you think this will correctly handle the NIL exceptions?