[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] MacPerl scripts as BBEdit Includes



This is both a MacPerl question, and a BBEdit question:

I'm still working on using XML::RSS in BBEdit.  The scripts to create and parse RSS files work fine as BBEdit filters, but rss2html.pl is really intended to be used as an include.

I try the following:

<!-- #bbinclude rss2html.pl "http://www.mycoinfo.com/downloads/mycoinfo.rdf" -->
<!-- end include -->

BBEdit returns the following error:

File index.html; Line 35:
An error occurred while including the script ³rss2html.pl²: MacPerl error type ³2².

and places this error message in the updated file:

# 
not well-formed at line 6, column 69, byte 249
File 'MyrmiDonna:Applications:Development_Tools:MacPerl Ÿ:site_perl:XML:Parser.pm'; Line 168

Below is the script in question.  It needs XML::Parser and XML:RSS, both available from CPAN <http://cpan.perl.com/>

#!/usr/bin/perl -w
# 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
# Slightly modified to produce nicer-looking html.

# INCLUDES
use strict;
use XML::RSS;
use LWP::Simple;

# Declare variables
my $content;
my $file;

# MAIN
# check for command-line argument
die "Usage: rss2html.pl (<RSS file> | <URL>)\n" unless @ARGV == 1;

# get the command-line argument
my $arg = shift;

# create new instance of XML::RSS
my $rss = new XML::RSS;

# 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;
<table border="0" width="184">
<tr>
<td bgcolor="#000000">
<table cellspacing="1" cellpadding="8" border=0 width="100%">
<tr>
<td valign="middle" align="center" bgcolor="#cccccc">
<font face="Arial,Helvetica">
<b><a href="$rss->{'channel'}->{'link'}">$rss->{'channel'}->{'title'}</a></b>
</font>
</td>
</tr>
<tr>
<td bgcolor="#ffffff">
HTML

    # print channel image
    if ($rss->{'image'}->{'link'}) {
	print <<HTML;
<center>
<p><a href="$rss->{'image'}->{'link'}"><img src="$rss->{'image'}->{'url'}" alt="$rss->{'image'}->{'title'}" border="0"
HTML
        print " width=\"$rss->{'image'}->{'width'}\""
	    if $rss->{'image'}->{'width'};
	print " height=\"$rss->{'image'}->{'height'}\""
	    if $rss->{'image'}->{'height'};
	print "></a></center><p>\n";
    }

    # print the channel items
    foreach my $item (@{$rss->{'items'}}) {
	next unless defined($item->{'title'}) && defined($item->{'link'});
	print "<font size='-1'><a href=\"$item->{'link'}\">$item->{'title'}</a><br><br></font>\n";
    }

    # if there's a textinput element
    if ($rss->{'textinput'}->{'title'}) {
	print <<HTML;
<form method="get" action="$rss->{'textinput'}->{'link'}">
$rss->{'textinput'}->{'description'}<br> 
<input type="text" name="$rss->{'textinput'}->{'name'}"><br>
<input type="submit" value="$rss->{'textinput'}->{'title'}">
</form>
HTML
    }

    # if there's a copyright element
    if ($rss->{'channel'}->{'copyright'}) {
	print <<HTML;
<p align="right">
<sub>$rss->{'channel'}->{'copyright'}</sub>
</p>
HTML
    }

    print <<HTML;
</td>
</tr>
</table>
</td>
</tr>
</table>
HTML
}

__END__

Brian McNett, Webmaster
*************************************************************
Mycoinfo. The world's first mycology e-journal.
http://www.mycoinfo.com/
*************************************************************


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org