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