printf dot net - Perl
I dream in Perl sometimes. Last night I dreamt in make. It sucked.


Pages

Home
CV
Perl

Code

create-rss
dynupdate
dizzy
lj-mood
lj-music
umistboard
md5-page
birthmonths
compact
passwd

Right, here we go:

  • create-rss.txt - While I was setting up a mirror for the cryptography site munitions.vipul.net, I noticed that an RSS feed of the latest updates on the site wasn't available - this script parses the news page's html and generates RSS from it. Uses LWP::Simple, HTML::TokeParser and XML::RSS, and comes in at 22 lines of code. It's still being run on munitions, and you can see the RSS it outputs, along with a screenshot of Evolution parsing the RSS.

  • dynupdate.txt - I got my first broadband connection from home recently, and wanted to sign up for a dynamic dns account. My desktop machine, though, runs FreeBSD, and the dyndns site only had update clients for Windows, linux executable and bash script. My perl solution only uses nine lines of perl, works via IO::Socket, and is available from dynup.net's client pages.

  • dizzy.txt - This script was written for a friend, to show an example of using CGI.pm. It prints an html page asking for a server-side filename and a search string and returns the number of matches of the string in the filename. It's thirty-six lines long.

  • lj-mood.txt - This script is the first of two written to provide statistics for users of livejournal.com, an on-line diary hosting site. The site allows you to define a current mood when you update, and my script logs in, retrieves all journal entries as if it were a full client, and populates a hash of mood => prevalence. It then uses GD::Graph::pie to draw a pie chart of the moods/popularity. It's 44 lines of code, and also uses IO::Socket for the connection. There's a sample chart (based on my own entries) here. The least prevalent mood is 'working'. :-)

  • lj-music.txt - LiveJournal also allows the user to give a 'Current Music' field. This script uses much the same technique as the last to round up all of these entries. It then discards the track titles, and counts the occurences of each artist before sorting by artist popularity and printing. It's fifty lines exactly, and there's sample output here.

  • umistboard.txt - We have a wwwboard for use by the Computation Department here at UMIST. It puts every message header on the index page, though, and is starting to get popular - meaning that several hundred kilobytes of html needs to be downloaded before you can get in to post. For those of us not using the 10Mbit connections in halls, I wrote a script to take a subject/body from the command-line and post it as a message. There's an added benefit of it remembering your user details, too, so you just have to type the message. It's 43 lines, and here's an example session transcript.

  • md5-page.txt - Also for the wwwboard at UMIST, but written generalised. This script takes a {web page,e-mail} address, and uses Digest::MD5 along with LWP::Simple and Mail::Sendmail to keep track of whether a page has changed, mailing the address given when it does. It's 72 lines long.

  • birthmonths.txt - After a debate on the London Perlmonks mailing list about whether more geeks were born in winter or summer months, this script was created. It uses GD::Graph and CGI.pm to record birthmonths and plot pie charts showing the distribution between summer and winter months, and between months (1..6)/(7..12). If you want to add your month of birth to the list, the active script is here.

  • compact.txt - After a post to the beginners@perl.org mailing list asking for help condensing a list in the style of '1,2,5,7,8,10,13' to '1-2,5,7-8,10,13', I wrote a solution; it's 64 lines in length. Shortly after posting it, Japhy came up with a regexp that made mine look bloaty, but it was still fun to write. Update: Simon pointed out that this is newsrc format, and that it can also be managed with Set::IntSpan. This script is finally completely redundant, probably. :-)

  • passwd.txt - This was written for Andy, who provides void's co-location. He needed a script to verify a user's username and password against an /etc/master.passwd file, with the file containing a mix of crypt() and unix_md5_crypt() hashes. My solution is 46 lines, and uses Crypt::PasswdMD5.

I've recently released my first module to the CPAN - it's a perl interface to the PGP WWW keyservers, and it's called PGP::FindKey. You can get at it by running perl -MCPAN -e 'install PGP::FindKey' from a shell prompt, or from the page for it on search.cpan.org.

.. and now I've written a few more. There's GraphViz::Zone, graphing hosts from BIND zone files; it outputs pretty pictures of your DNS zones, like this one of my (now-ex) home network, and there's base::Glob, which brings Java-style 'import java.foo.*' statements to Perl by allowing globbing on base.pm through crawling the symbol table.

I'm also a fan of JAPHs, which are small-but-obfuscated scripts that print.. well, you'll see. Maybe. This one works under Mac OS X and Redhat/Mandrake, but I can't guarantee much else:

chris@lexis:~$ perl -le'@a=($^O eq 'darwin')?qw(100453 81289 9159):qw
(23152 19246 2040);while(<>){chomp;push @b,$_ if grep {$.==$_}@a}push
@b,$^X;print ucfirst join(" ",@b[2,0,3,1]).","'</usr/share/dict/words