Perl

As a diversion from my PhD, I decided to learn Perl. Although I basically started to use it as a) an excuse not to do real work, and b) as a form of one upmanship on my husband (who can "only" program Fortran), I've since become addicted and cannot believe I ever managed to do anything without it. Here are a few useful offerings.

Tutorial

Probably the most useful thing here is my perl tutorial, which covers just about enough to make you dangerous.

Requests for anything else (except how to program XS, as there are limits to my patience, and this is one nut I have yet to crack) can be directed to me and I'll do my best to help.

Math::Calculator

My all-singing all-dancing perl calculator. All I could find in the way of simple perl calculators via Google were things along the line of "…perl -e 'while (<STDIN>) {eval; print "$_\n"}' works fine for me…" but this didn't work too fine for me (besides, perl -ple "$_=eval" is quicker), and I'd worry about misspeeling 2+2 as system "rm -rf *". So I bodged together a little script, mostly because I'd left my old scientific calculator at home (the very first Casio with full screen graphics, which was dead cool when I was at school about a century ago), which over the last two years has slowly grown into a fully fledged parser (Parse::RecDescent) and interpreter that can be used as a conventional OO module or called as a shell using:

perl -MMath::Calculator -e shell

à la CPAN. This may be considered overkill, as it now takes about 3 000 lines of code to add 1 and 1. However, it can deal with scalars, matrices, vectors, base-n and complex numbers, and has a well-defined extension API.The Math::Calculator modules are available in this tarball. If you're happier with ActiveState's PPM, then open a cmd shell and type:

ppm install http://www.steve.gb.com/perl/downloads/Math-Calculator-3.00.ppd

Bio::PrisonersDilemma

This module provides all the basic functions to run a prisoners' dilemma tournament as popularised by The Selfish Gene. It allows you to set up the conditions for a tournament, run round-robins and true tournaments, cull and breed according to scores gained, write your own strategies, or use the built-in code for famous strategies like always-cooperate, tit-for-tat, always-defect and simpleton, and generate reports during and after the tournament. Get the Bio::PrisonersDilemma distribution here, or use PPM:

ppm install http://www.steve.gb.com/perl/downloads/Bio-PrisonersDilemma-1.02.ppd

Tk::Taxis

This module implements a Tk widget that simulates the movement of bacteria. Bacteria sense which direction to move in by comparing e.g. the concentration of sugar they are experiencing right now with what it was just a moment ago. If they find that it has increased, they suppress tumbles (random changes in direction). If they sense they are going down the concentration gradient on the other hand, they tumble more often. This overall motion is called taxis and results in a biased random walk that on average gets the bacteria out of trouble and into food. There are various configurable options (such as the tumble frequency, size of canvas, population size and taxis direction preference), and the API allows easy extension of the images that can be displayed for the critters in addition to two default image sets (bacteria and woodlice).

screenshot of Tk::Taxis.
Screenshot of Tk::Taxis with woodlice

In the eg directory, you will find a script called woodlice.pl, which is a fully functional and configurable GUI using the Tk::Taxis widget and saving you the effort of writing a simulation: a screenshot of the script with the default settings is above. Invoke it with wperl for a fully GUI experience. Download the Tk::Taxis package here, get current and older versions from my CPAN directory, or use PPM:

ppm install http://www.steve.gb.com/perl/downloads/Tk-Taxis-2.03.ppd

If you really must, there is also a PAR executable version of the woodlice script, in zipped format for Windows, which you can install by merely unzipping and running the setup batch file. YMMV if you're not running under Windows XP, but you can use this executable if you can't or won't install perl for some reason.

See lesson 21 for details of how it works and how to do similar things yourself.

WebCT::Quiz

This is a filter-style module for converting a simple markup for multiple-choice questions and answers into the horrible twistly mess of colons that the virtual learning environment WebCT requires of its quiz file importation format. Basically it turns this:

# Category of question
> Title of question
1. Text of question?
a. Wrong answer.
~ You idiot!
*b. Correct answer.
~ Well done!

into something importable to the WebCT question database. It also handles explicit and implicit scores, general feedback, all-or-nothing multiple-answer questions, negative marking and answer layout; and it also has some sanity checking to prevent you from creating questions that can only score 0%. It works for all my test cases, and for the 500 questions I've made for my undergrads, so I think it's reasonably robust and does the right thing in the way of defaults when information is not supplied. It also has support for short-answer questions and matching-answer questions, and can now output both WebCT CE4 flat text import files, and the CE6 zipped XML things:

Download the WebCT::Quiz package here, or use PPM:.

ppm install http://www.steve.gb.com/perl/downloads/WebCT-Quiz-3.01.ppd

ppt2doc.pl

ppt2doc.pl converts my PowerPoint lecture presentations to Word document lecture notes. Although it's a bit specific to my lecture problem-space, it's all done in Win32::OLE and might serve as a very useful PowerPoint/Perl Win32::OLE primer, since I've never found anything remotely as comprehensive as this online before. It shows how to transfer tables, text, title placeholders and pictures using just the PowerPoint and Word APIs, and could be easily modified to output e.g. HTML instead.