Dear Monks,

Continuing on the ATOM parsing question, I have extracted a snipped of response from a CDATA section which contains more XML. Monk Jenda's very fine suggestion was to re-parse. However, I am getting a:

Undefined subroutine &main::read_chunk_of_data called at quake_parsing +_9 line 81.

response from the system. I copied the 'example' straight out of CPAN but it seems that the call I'm making is not valid. The entire program is included below and the issue seems to occur around line 82 (now marked with a bunch of asterisks).

#!/usr/bin/perl -w use XML::FeedPP; use XML::LibXML; use XML::Rules; use LWP::Simple; use Time::Piece; use strict; use warnings; # ----------------------------------------------- # open the quake marker file for writing # ----------------------------------------------- open (quake_marker, '>/Users/coblem/xplanet/markers/quake.txt') or die + $!; # ----------------------------------------------- # get the Atom feed from the USGS # ----------------------------------------------- #my $source = '/Users/coblem/xplanet/quake/quake.xml'; #use this line +only for local testing my $source = 'http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary +/4.5_day.atom'; #use this line for feed testing my $feed = XML::FeedPP->new( $source ); # get the date and time. While not needed right now, this will help l +ater with managing expired # data. # ----------------------------------------------- # get date and time, day of the year # ----------------------------------------------- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(t +ime); $year += 1900; my $cur_time = "$wday $mday $mon $year, $hour:$min:$sec"; # ----------------------------------------------- # update the output file header # ----------------------------------------------- my $dayofYear = localtime[7]; print (quake_marker "# This Quake file created by quake_parsing_9", "\ +n"); print (quake_marker "# Matt Coblentz; Perl version unknown", "\n"); print (quake_marker "# For more information, see the USGS website", "\ +n"); print (quake_marker "# Last Updated: ", $cur_time, "\n", "\# \n"); # Incorporating a rules section so that we can extract the information + from the CDATA section # and any other specific fields we might need. First attempt will be +to pull the 'Updated' # field data from the Atom feed. I tried to follow the example in the + CPAN summary but I'm # clearly lost. # PerlMonk Jenda pointed out that I should use the standard rules prev +iously defined. There were # other helpful comments about the author and update rules as well, wh +ich are now deprecated. my @rules = ( _default => 'content', dd => 'content trim', ); my $parser = XML::Rules->new(rules => \@rules); # Need to convert the feed object to a string. Thanks to PerlMonk Fro +zenwithjoy my $atom = $feed->to_string(); $parser->parse( $atom ); # This section extracts the title field, then performs string manipula +tions to extract the # long location data and the magnitude. Funny that USGS does not have + a magnitude field # in this feed. foreach my $quake( $feed->get_item() ) { my $title = $quake->title(); my $place = substr($title, 8); my $magnitude = substr($title, 2,3); # Thanks to PerlMonk Jakeease for fixing these extractions: my $id = $quake->get( "id"); my $update = $quake->get( "updated" ); my $location = $quake->get( "georss:point"); # *********************************************** # *********************************************** # THIS IS THE PROBLEM AREA! # *********************************************** # *********************************************** my $summary = $quake->get( "summary"); print $summary; while ($summary = read_chunk_of_data()) { $parser->parse_chunk($summary); } my $data = $parser->last_chunk(); my $dd = $data->get( "dd"); print $dd, "\n"; # print (quake_marker $location, "\"\" color=Yellow symbolsize=65", + "\n"); # print (quake_marker $location, "\"", $magnitude, "\" color=Yellow + align=Above", "\n"); # print (quake_marker "\n"); print (quake_marker "\n", "Magnitude ", $magnitude, " ", $place, " +\n"); print (quake_marker $location, " \"\" color=Yellow symbolsize=65", + "\n"); print (quake_marker $location, " \"", $magnitude, "\" color=Yellow + align=Above", "\n"); print "\n"; } close (quake_marker);

What am I doing wrong? I'm obviously invoking something that isn't there, but what should it be?


In reply to XML parsing with XML::Rules by mcoblentz

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.