Friday, December 12, 2003

Knit One Perl, Too

Here's my code that generates the list currently sitting on the right-hand side of this page, taking an export from SharpReader as something.opml:

open FILENM or die;
print "<ul>";
while(defined($line = <FILENM>))
{
$line =~ s@<outline type="rss" title="([^"]*)" description="([^"]*)" xmlUrl="([^"]*)" htmlUrl="([^"]*)" />@<li><a href=\"$4\" title=\"$2\">$1</a> - <a href=\"$3\" title=\"feed for $1\">feed</a></li>@ and print "${line}\n" and next;

$line =~ s@<outline title="([^"]*)">@<li>$1</li><ul>@ and print "${line}\n" and next;
$line =~ s@</outline>@</ul>@ and print "${line}\n" and next;
}



I know I should take advantage of $_ instead of using $line. I always forget the semantics, though.

No comments: