I think the Slashdot Headline Grabber is a good idea. I only have one question: why not using LWP to get the /. xml page? I think it's better, and using LWP it is possible to set up a proxy (very useful if you are beyond a firewall). I hacked your code a bit, and here are my suggestions:
use LWP;
use HTTP::Request::Common;
#
# ....
#
sub fetch_headlines {
my @D;
my $ua = new LWP::UserAgent;
return 0 unless ($ua);
$ua->proxy('http', 'http://myproxy.mynet.org:8080'); #set up your
+proxy here
my $url = "http://www.slashdot.org/slashdot.xml";
my $res = $ua->request(GET $url);
if ($res->is_success) {
@D = split /\n/, $res->content;
} else {
return 0;
}
my ($title, $url);
for (@D) {
$title = $1 if /\<title\>(.*)\<\/title\>/;
$url = $1 if /\<url\>(.*)\<\/url\>/;
if (/<\/story>/) {
$stories{$url} = $title;
push(@keys, $url);
$title = "";
$url = "";
}
}
return 1;
}
It may also be a good idea to use XML::DOM to parse the XML downloaded from /. but that is probably too much for the Headline Grabber: the for loop is quicker.
Any comment is highly appreciated.
marcos