#!/usr/bin/perl # rss2html - converts an RSS file to HTML # It take one argument, either a file on the local system, # or an HTTP URL like http://slashdot.org/slashdot.rdf # by Jonathan Eisenzopf. v1.0 19990901 # See http://www.webreference.com/perl for more information # INCLUDES use strict; use warnings; use XML::RSS; use LWP::Simple; # Declare variables my $content; my $file; binmode STDOUT, ":encoding(utf8)"; # MAIN # check for command-line argument die "Usage: rss2html.pl ( | )\n" unless @ARGV == 1; # get the command-line argument my $arg = shift; # create new instance of XML::RSS my $rss = XML::RSS->new; # argument is a URL if ($arg=~ /http:/i) { $content = get($arg); die "Could not retrieve $arg" unless $content; # parse the RSS content $rss->parse($content); # argument is a file } else { $file = $arg; die "File \"$file\" does't exist.\n" unless -e $file; # parse the RSS file $rss->parsefile($file); } # print the HTML channel print_html($rss); # SUBROUTINES sub print_html { my $rss = shift; print <<"HTML";
$rss->{'channel'}->{'title'}
HTML # print channel image if ($rss->{'image'}->{'link'}) { print <<"HTML";

$rss->{'image'}->{'title'}{'image'}->{'width'}\"" if $rss->{'image'}->{'width'}; print " height=\"$rss->{'image'}->{'height'}\"" if $rss->{'image'}->{'height'}; print ">

\n"; } # print the channel items foreach my $item (@{$rss->{'items'}}) { next unless defined($item->{'title'}) && defined($item->{'link'}); print "

  • {'link'}\">$item->{'title'}
    \n"; } # if there's a textinput element if ($rss->{'textinput'}->{'title'}) { print <<"HTML";
    $rss->{'textinput'}->{'description'}

    HTML } # if there's a copyright element if ($rss->{'channel'}->{'copyright'}) { print <<"HTML";

    $rss->{'channel'}->{'copyright'}

    HTML } print <<"HTML";
  • HTML }