Putting data onto a site that is retrieved from other sources is a piece of cake with Perl. This can be done for much more important things than placing article headline from a blog onto a page. Here is the code I created to do it, although it is rough cheap and dirty … PHP may be a better choice when interfacing to a shopping cart system.

#!/usr/local/bin/perl

print “Content-type: text/html\n\n”;

# setup for http request … simple could of been used, but …

use LWP::UserAgent;
$ua = new LWP::UserAgent;
$ua->timeout(15);

$url = “http://at-the-water-cooler.com/blog/category/web-developement/feed”;

# get html
open(HTML, “index.html”);
$good = read HTML, $html, 250000;
close(HTML);

# do custom SSI, verb is [feed]

while ($html =~ /\[feed\]/s) {

print “$`”;
$html =”$’”;

$req = new HTTP::Request ‘GET’ => $url;
$page = $ua->request($req)->as_string;
$page =~ /\n\n/;
$header = “$`\n”;
$body = “$’”;

# this is my own feed, I’m not going to hack my own site, so I not going to try to prevent
# myself from hacking it.

while ($body =~ /<item(.+?)<\/item>/s) {
$body = “$`$’”;
$data = $&;
$data =~ /<link>(.+?)<\/link>/;
print “<dt><li> <a href=’$1′>”;
$data =~ /<title>(.+?)<\/title>/;
print “$1<\/a>”;
$data =~ /<pubDate>(.+?)<\/pubDate>/;
print “<dd><small>$1</small>\n”;
}
}
# if no feed, $html is intact, else it is rest of the page.

print “$html”;

After setting up the script to execute change .htaccess to:

DirectoryIndex mefirst.pl index.html index.shtml

This is a 30 minute script and there are others for free on the internet.

Popularity: 7% [?]

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word