Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/perl -w
    
  2. or download this
    
    use strict;
    ...
    use LWP::Simple;
    
    my $feed;
    
  3. or download this
    open( FH, ">feed.xml") or die "Error: $!\n";
    
  4. or download this
    $feed = get("http://rss.news.yahoo.com/rss/science");
    
  5. or download this
    print FH $feed;
    
  6. or download this
    my $parser = new XML::Parser ( Handlers => {
                                   Start   => \&hdl_start,
                                   End     => \&hdl_end,
                                   Char    => \&hdl_char,
                                 } );
    
  7. or download this
    $parser->parsefile("feed.xml");
    
  8. or download this
    
    sub hdl_start {
    ...
        my ($p, $ele, %attribs) = @_;
        $attribs{'string'} = '';
        $feed = \%attribs;
    
  9. or download this
    }
    
    ...
        my ($p, $ele) = @_;
        display_feed($feed) if $ele eq 'title';
        display_feed($feed) if $ele eq 'link';
    
  10. or download this
    }
    
    ...
       no strict 'refs';
    
       $feed->{'string'} .= $str;
    
  11. or download this
    }
    
    sub display_feed {
    
       my $attribs = shift;
    
  12. or download this
       $attribs =~ s/\n//g;
    
  13. or download this
       print "$attribs->{'string'}\n\n";
    
  14. or download this
    }