#!/usr/bin/perl -w # Here, we're calling two modules or additions to Perl. The first one we # installed on the server specifically for this occasion, but 'use # strict' is a helpful little addition if you want to write good code. # It catches a lot of the human idiocy that plagues horrible programs. use XML::RSS; use strict; # create some variables near the top of the script so we don't # have to search through the script later to change them. my $headlines_file = "/path/to/headlines.html"; my $rss_output = "/path/to/headlines.rss"; # we create a new rss object. my $rss = new XML::RSS (version => '0.9'); # these are just little descriptive elements of the RSS channel we're # about to make. we add them to the $rss object we made above. $rss->channel(title => "Your Site Name", link => "http://www.yoursitename.com/", description => "Headlines from Your Site Name!", ); # we open the file with our headlines in it. open(FILE, "<$headlines_file") or die "Couldn't open $headlines_file: $!"; # a traditional while loop. for each line of our $headlines_file # we start looking for markers within the code that tell us a # headline is coming. in this example, we're assuming that headlines # follow html like

headline

. while () { # look in the current line to see if our headline is in there. if ($_ =~ /

.*<\/a><\/h2>/) { # if it is, then we grab the link and headline. my ($link, $headline) = /

(.*)<\/a><\/h2>/i; # if both $link and $headline were created, then we # add them to the $rss object using the add_item feature # of XML::RSS. if ($link and $headline) { $rss->add_item(title=>$headline, link=>$link ); } # move on to our next line. next; } } # if we're this far, we've finished our file. close(FILE); # finally, save the rss file. $rss->save($rss_output); # and quit. exit;