use warnings; use strict; use LWP::UserAgent; use XML::Simple; use XML::RSS; # pass in the URL for the newest nodes page, i.e. # http://perlmonks.org/index.pl?node_id=30175 sub process_xml { my $url = shift; my %authors; my @questions; my $browser = LWP::UserAgent->new(); $browser->timeout(30); my $response = $browser->get($url); die unless $response->is_success; my $tree = XMLin( $response->content ); foreach my $node ( @{ $tree->{AUTHOR} } ) { $authors{ $node->{'node_id'} } = $node->{'content'}; } foreach my $node ( @{ $tree->{NODE} } ) { my $item = { author => $authors{ $node->{'author_user'} }, node_id => $node->{'node_id'}, subject => $node->{'content'} }; push @questions, $item if $node->{'nodetype'} eq 'perlquestion'; } my $rss = new XML::RSS (version => '1.0'); $rss->channel( title => "perlmonks newest questions", link => "http://perlmonks.org", description => "perlmonks newest questions", ); for my $item ( @questions ) { $rss->add_item( title => $item->{subject}, link => "http://perlmonks.org/index.pl?node_id=" . $item->{node_id} ); } print $rss->as_string(); }