APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

© August 2003 Tony Lawrence

Simple RSS News Feed Generator

If you don't know what an RSS News feed is, see RSS Syndication Feeds and Why Do I Care?

So, you have a web site, and you want to generate an RSS feed. In my case, I have the entire process of adding anything to my site scripted (see The AutoMagic Web Site), and of course generating new RSS documents is just part of that. But you may not have reached that state yet, so here's a little Perl script that will help you along.

This asks you for new page information, and stores that in a file (or you can create the file manually or any other way you like). It then reads the file backwards, and generates an RSS file.

You can use this to create your own RSS News feeds, or just to see what the feed should look like. It's pretty simple code, so shouldn't be hard to understand.

I set the maximum number of RSS headlines to 15. You can change that, but keep two things in mind: some RSS News readers won't display more than 15 items anyway, and all RSS News readers are going to regularly request the RSS file from your site to see if anything has changed. If it's a big file, that can add up to a lot of bandwidth.

By the way, don't bother with this if you hardly ever add new pages to your site. It just isn't worth the trouble, and no one is going to care. But if you do add new pages regularly, you really want to do this: having an RSS feed improves your readers ability to find new content.

You'll enter three pieces of information for each page, separated by pipe symbols ("|"):

The URL:  https://yourweb.co/yourpage.html
A Title:  How to Medicate a Cat
A Description: I lose every time we try this!

The URL is where the page is on the internet, the title is what will be displayed in the RSS News reader, and often the description will show up when the user hovers over the title with their mouse, or it may appear in a separate box. So, you'd enter (in the file or at the keyboard):

https://yourweb.co/yourpage.html|How to Medicate a Cat|I lose every time we try this!

and so on. Here's the code:

# url of the generated file
# physical location
# title
$MY_TITLE="Site News for A.P.Lawrence Unix, Linux and Mac OS X Resources";
# description
$MY_DESC="Resources and information for Unix and Linux, and other computer related topics. Thousands of articles, reviews, consultants listings, skills tests, opinion, how-to's, suggestions and more for Unix, Linux and Mac OS X, netorking, web site maintenance and more.. ";
# where is the site
# your logo or other image
$MY_IMAGE_TITLE="A.P. Lawrence Logo";
# local storage for page info
# how many items to generate.
# you can make it larger, but some readers will only show 15, and you
# do need to stop somewhere.
open(O,">$MY_FILE") or die "How come $! $MY_FILE ?";
$year += 1900;
$AM="PM" if $hour > 12;
$update="$days[$wday], $mday $month[$mon] $year $hms GMT";
print O <<EOF;
<?xml version="1.0" encoding="iso-8859-1"?>
<rdf:RDF xmlns:rdf="https://www.w3.org/1999/02/22-rdf-syntax-ns#"
<channel rdf:about="$MY_RSSFILE">
<image rdf:resource="$MY_IMAGE">
for ($x=0;$x < 15;$x++) {
last if not $url[$x];
print O <<EOF;
<rdf:li rdf:resource="$url[$x]" />

print O  <<EOF;
<image rdf:about="$MY_IMAGE">

for ($x=0; $x < 15 ; $x++) {
last if not $url[$x];
print O <<EOF;
<item rdf:about="$url[$x]">
print O "</rdf:RDF>\n";
close O;

sub getnew {

print <<EOF;
Add new information; CTRL-D when done.
Enter: url|title|description
https://yourweb.com/cows.html|Cows of New Jersey|Examining the cow breeds of New Jersey farms
open(O,">>$MY_STORED_DATA") or die "Hey $! $MY_STORED_DATA";
while (<>) {
  last if $x == $MAX;
  print O $_;
close O;
open(O,"$MY_STORED_DATA") or die "Huh? $! $MY_STORED_DATA";
@webpage=<O>;close O;
foreach (reverse @webpage) {
  last if $xcnt == $MAX ;
  ($link,$title,$desc)=split /\|/;

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> Simple RSS News Feed Generator in Perl

Inexpensive and informative Apple related e-books:

Take Control of Pages

Take control of Apple TV, Second Edition

Take Control of Preview

Take Control of Numbers

Take Control of iCloud, Fifth Edition

More Articles by © Tony Lawrence

Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Printer Friendly Version

Never let a computer know you're in a hurry. (Anonymous)

Linux posts

Troubleshooting posts

This post tagged:




Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode