Simon's Journal Simon's use Perl Journal en-us use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners. 2012-01-25T02:01:59+00:00 pudge Technology hourly 1 1970-01-01T00:00+00:00 Simon's Journal Moved! Want to follow my blog without ever leaving use.perl? The <a href=";bid=simoncozens">use.perl RSS Feed</a> lets you check up on me without leaving the house! Simon 2002-07-23T08:12:59+00:00 journal Goodbye <a href="">Blosxom</a> is lovely, and lets me take my blog <a href="">home</a>. So I'll be writing from there from now on. Oh, yes, and importing the use.perl blog into blosxom was quite fun. <p> So, bye for now, hope you'll catch the blog at its new home - oh, and <code>Config::Auto</code> is out.</p> Simon 2002-07-04T22:43:03+00:00 journal WANT TO GO HOME! I want to go home, but I've got started hacking a really neat little Perl module, and I've only got two subroutines left to do. In fact, stuff it, I'm going home. I can finish this off tomorrow.<p> So, about the module. It's called <code>Config::Auto</code>, and I've written it because I never want to write another config file parser ever again. So, this little baby looks around for a likely-looking config file, sniffs it to work out what sort of format it's in, and has a good shot at parsing it into a Perl data structure. It deals with XML, INI files, Perl files, lists and the more "vague" Unix-style colon-separated, equal-separated and space-separated files. </p><p> For instance:</p><blockquote><div><p> <tt>#<br>use Config::Auto; use Data::Dumper;<br>print Dumper(Config::Auto::parse());</tt></p></div> </blockquote><p> This looks around my filesystem, and finds<nobr> <wbr></nobr><code>.tortuousrc</code>, which looks like this:</p><blockquote><div><p> <tt>test: foo=bar, baz=quuz<br>test2: blah<br>blez: quux</tt></p></div> </blockquote><p>And, with no other prompting, it comes back with:</p><blockquote><div><p> <tt>$VAR1 = {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'test2' =&gt; 'blah',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'blez' =&gt; 'quux',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'test' =&gt; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'foo' =&gt; 'bar',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'baz' =&gt; 'quuz'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;};</tt></p></div> </blockquote><p>Laziness: check.<br> Impatience: check.<br> Hubris: check.</p> Simon 2002-07-03T17:14:29+00:00 journal Some thoughts on donation models In reply to a thread on Free Software Business:<blockquote><div><p> I have two problems with the open source donation model. </p><p> The first is that open source projects are made from code, and the best donation I can give them is not money but code. In the case of Perl, I maintain nearly 40 modules, managed the release of the first few versions of the Perl 6 interpreter, and have contributed many patches and documents to the Perl 5 core. I feel absolutely no guilt at all for not giving a single cent to the fundraising drive. </p><p> If all we did was throw money at a small number of people to get the code written for us, there'd be no community to maintain. </p><p> Second, and far more seriously, donation models reinforce the myth that software is important in any meaningful sense of the word. Of course, software is relatively important to programmers, but for the vast majority of the world, it's pretty meaningless. </p><p> I'm very lucky that I have the opportunity to give reasonable sums of money to charity reasonably often. When this happens, I naturally have a number of things vying for my donations. Here are a few:</p><ul> <li> Work with homeless people in my home town.</li> <li> Care for the elderly mentally ill.</li> <li> Providing AIDS vaccines for children in Africa.</li> <li> Digging wells and providing fresh water for villages in Pakistan.</li> <li> Allowing privileged first-world programmers to sit in front of a computer for more hours than they currently do.</li> </ul><p> Put like that, I hope it is clear that software is not as important as the biased eye of a programmer may perceive. Indeed, no matter how much of my income I derive from the existence of a given open source project, it becomes very difficult for me to fail to take a global view in cases like this. The common counterargument that I should donate money to Perl because it provides my livelihood makes sense only for those who cannot see beyond their own needs. </p><p> Meanwhile, I know full well that as Perl <b>is</b> an open source project, it'll continue to be maintained and developed whether or not people are paid to do this. This makes it even more difficult for me to help the poor white-bread middle-class afflicted. </p><p> So I'm happy to contribute to Perl in my own way, but I'd rather not lose my sense of priority.</p></div> </blockquote> Simon 2002-07-03T15:59:34+00:00 journal Idea of the day I've just written something using Leon's excellent <code>GraphViz</code> module to turn a Shishi parser into a nice diagram of the state machine. While GraphViz turns a data structure into a graph, it would be really lovely for parser tuning to be able to play around with the graph in dotty and then read the resulting graph back into a data structure... Simon 2002-07-03T13:21:03+00:00 journal Class::Dynamic released This is a module I threatened to release to the world a while back. Do evil things with it...<blockquote><div><p> <tt>=head1 NAME<br> <br>Class::Dynamic - Rudimentary support for coderefs in @ISA<br> <br>=head1 SYNOPSIS<br> <br>&nbsp; package Blargh;<br>&nbsp; use Class::Dynamic;<br>&nbsp; our @ISA = ("Foo", sub { rand &lt; 0.5 ? "Bar" : "Baz" } );<br> <br>=head1 DESCRIPTION<br> <br>This module allows you to insert coderefs into a class's C&lt;@ISA&gt;.</tt></p></div> </blockquote> Simon 2002-07-02T16:37:11+00:00 journal Home and tired I got back from YAPC yesterday after a reasonably sleepless night flight. I was slightly suspicious to find my mail sorted and the kitchen tidied. But I was too tired to work out what was going on, so had a bath and forced myself into work, which was possibly a bad idea. I took the rest of the day to catch up with what's been going on here, and then returned home to find, yes, I had indeed acquired a housekeeper.<p> By way of explanation, a friend had been staying with someone who's since moved back to Japan; she then planned to move to Cheltenham, leaving her bags at my house for the time being. However, the Cheltenham idea also fell through and she was stuck in Oxford homeless. So she's staying with me for now. </p><p> At the airport on the way back, I managed to get a lot more done on Shishi, and so I've released the prototype to CPAN; I've also got a reasonable stab at an approximate Perl 6 regular expression compiler which compiles to a shishi parser. Unfortunately, it's got to the point where it's really very difficult to build up the data structures that I need from a simple-minded tokenization of a Perl 6 pattern, and I'm left trying to bootstrap Shishi by hand-coding a parser. This is not fun. </p><p> This morning, we finished the 6 week Perl course I've been teaching. We did half the lesson on CPAN modules, looking primarily at the modules in my "10 modules" talk from YAPC. Of course, we got to a demonstration of <code>LWP::Simple</code> just as the demonstration web server was being upgraded, so I had to puzzle over why one person's code worked fine, but someone else's identical code a few minutes later didn't work. In the second half, people built a news ticker utility out of <code>LWP</code>, <code>Mail::Send</code> and dodgy screen-scraping regexes. Good fun, and I think people finished the course with an idea of how to do relatively complex things in Perl - given that the previous course got to subroutines and just abruptly ended, I think adding the modules lesson was a big improvement. </p><p> And now, after a flight, a bad night's sleep, and about three hours teaching, I'm utterly shattered.</p> Simon 2002-07-02T13:51:14+00:00 journal Dispatches from STL 23/7/2002 - St. Louis <p> Woke up too early, and wrote a Perl 6 regular expression engine. Don't you just hate it when that happens? </p><p> At 6:30, I headed off to find some coffee, which was more of an ordeal than I expected. The hotel's on the edge of quite a small town, and nothing opens until at least 7am. Finally, I wandered down past Concordia seminary, and found a lovely little cheap and tasty coffee bar on the corner. I got my stuff together and around 8:30 I was ready to head into St. Louis itself. </p><p> This town, as a famous man once said, is coming like a ghost town. St Louis is a weird, weird place. The car culture has driven a few of the usual things you'd expect to see in a city out to the suburbs. Basic things like "shops" and "people". Until around noon today, there was essentially nobody on the streets apart from me. (Granted, it was a Sunday.) </p><p> Even when the city started to liven up, I couldn't help noticing, while I was wandering around, that there wasn't really a central business district. There were a few delis, pharmacies and 7/11s dotted around, but not even so many of those. Instead, many of the downtown streets were filled with empty buildings, boarded up doors and the shells of long-dead shops. It was bizarre. Some of the most wonderful urban architecture I've seen in a prime position in the city center was just lying empty and forgotten. Even the St. Louis Center, a four storey shopping and restaurant complex, hadn't really taken off. Many of the units remained closed, and those which were let were not exactly inspiring. </p><p> The only signs of real civilization were the Busch baseball stadium, - complete with crowds of mourners for legendary baseball radio announcer Jack someone-or-other - the old Union Station, - now a restaurant complex - and the Gateway Arch - long queues and tight security. It took me half the day to find somewhere which would sell batteries, and then I took another few hours taking pictures of some of the great yet desolate buildings I'd seen. Finally, an hour long trip on a Mississippi steamer, before ordering a van ride back to the hotel. Then writing, writing, writing. </p><p> The language barrier is turning out to be a problem. I ordered a cheesesteak from the St. Louis Center when it finally opened, and was startled to be asked by the server "Why do we pray?" Well, I wasn't really in the mood for theological discussions, so I just shrugged. This wasn't enough. "Why do we pray?" This a trick question, isn't it? The server got agitated, and picked up two bags of rolls. "Why do we pray?" </p><p> Realisation dawned. "Oh, um, wheat, please."</p> Simon 2002-06-25T15:33:17+00:00 journal Tired Tonight, I: reviewed four chapters of galleys, ported Magicpoint to OS X, (No, I didn't ever enter the command <code>vi<nobr> <wbr></nobr>/usr/include/stdio.h</code>, no, not at all.) ran over my tutorial for tomorrow, despatched for the week, and had a few drinks with co-workers. <p> I think I'm allowed to feel tired after that.</p> Simon 2002-06-19T23:06:24+00:00 journal Twin peaks <a href="">Submitted without comment.</a> Simon 2002-06-19T16:03:11+00:00 journal Great Minds Think Alike. Today Arnar Hrafnkelsson asked my opinion on a module he'd been working on called <code>Regexp::Open</code>. It's neat, it's a state machine implemented in C with an XS interface to it. I took a look at it and realised the concept looked a little familiar. <p> He was just telling me about how he could use it to dynamically change the state machine at runtime when I pointed him at the <a href="">shishi repository</a>...</p> Simon 2002-06-19T15:35:36+00:00 journal People are ingenious On the Perl course I'm doing, I give out a lot of programming assignments. Last week, people wrote something to get five names and favourite colours from the user, stored each one into a hash, and then wrote out the hash as a colon-delimited file. <p> This week, I showed them about <code>split</code> and asked them to write something to read the hash back in, and prompt for a name, then display that user's favourite colour. One of the students - a bright girl - said "Why should I use a hash?" and came up with something like this:</p><blockquote><div><p> <tt>use strict;<br>open IN, "favourites.txt" or die $!;<br> <br>print "Who do you want to know about? ";<br>my $input = &lt;STDIN&gt;;<br>chomp $input;<br> <br>while (&lt;IN&gt;) {<br>&nbsp; &nbsp; chomp;<br>&nbsp; &nbsp; my ($name, $colour) = split<nobr> <wbr></nobr>/:/;<br>&nbsp; &nbsp; if ($input eq $name) {<br>&nbsp; &nbsp; &nbsp; &nbsp;print "$name's favourite colour is $colour\n";<br>&nbsp; &nbsp; }<br>}</tt></p></div> </blockquote><p> What can you say? It's decent code, it fulfils the spec, it just wasn't exactly what I had imagined. Ah, the fun of TMTOWTDI...</p> Simon 2002-06-18T13:10:35+00:00 journal Doublethink This is not a pointed question; I honestly don't know the answer.<p> The reason the US government publically gives for moves against Iraq and Saddam Hussain is that Iraq is trying to develop "weapons of mass destruction" - nuclear weapons. Developing nuclear weapons is obviously a big no-no, which is why Iraq had to have the UN weapons inspectors in. </p><p> If this is the real reason (which I really doubt that it is) then why didn't America send the boys in when India or Pakistan went nuclear? And what goes on in the minds of these government folk that they can simultaneous believe that developing nuclear weapons is such a venial sin that we ought to go and assassinate the President, but the fact that the US already <b>has</b> nuclear weapons is good and proper? Obviously it's a flimsy excuse, but why has nobody called them up on it?</p> Simon 2002-06-17T17:57:04+00:00 journal Semantic ambiguity <p>"Free to good home - Baby carrying rucksack"</p> Simon 2002-06-17T08:41:41+00:00 journal ActiveSnake ActiveState are now apparently profitable; much of this can be explained by their shift towards Python support and services. <p> The phrase "snake oil" takes on a whole new meaning.</p> Simon 2002-06-16T21:33:57+00:00 journal What trouble a few careless words can cause. <p>I have agreed to become a children's church assistant. (Which is obviously the PC version of "Sunday school teacher".) You are free to imagine your favourite BOFH attempting humility, patience and kindness towards a bunch of screaming five-to-thirteen year olds.</p> Simon 2002-06-16T19:52:22+00:00 journal Synopsis 5 <a href="">This</a> didn't get much attention, so here's another mention of it. Simon 2002-06-15T07:01:16+00:00 journal Thanks, Gisle! <p>LWP rocks. We all know that. But when was the last time you sat down and thought about the fact that someone actually coded it, rather than it being the gift from above it might behave like?</p> Simon 2002-06-15T06:58:23+00:00 journal Dream or nightmare? <p>You can tell it's a nightmare if it has clowns in it.</p> Simon 2002-06-15T06:29:26+00:00 journal Acme::Rant <a href="">Acme::Fscking::Buckaroo</a>.<p> Call me a boring young fart, (but you knew that already, right?) but I'm still amazed how many people can copy a <a href="">mildly amusing idea</a> and still think they're being original and amusing. </p><p> So you can do source transformation. Good for you. Don't people have either better or at least more amusing things to write? I guess not. </p><p> It's getting even more tedious than quoting the <a href="">Four Yorkshiremen</a>.</p> Simon 2002-06-14T11:16:30+00:00 journal Shishi <p>The Perl prototype to shishi managed to match "abc" today. From here on, getting the regular expression engine part of the runtime together is a SMOP; ensuring that the parsing side of it works as well is slightly more tricky. It's baby steps (and I'm going to take a few more days off to speed things up) but I'm still very excited about what's possible.</p> Simon 2002-06-13T21:22:11+00:00 journal Idea fairy <p>Selective tainting. "Taint all filehandles, but not environment accesses." Or even, "taint this filehandle, since it's coming in from the network, but not that one, since it's the server config file and I trust it". Difficult to implement in Perl 5 without a major slowdown, I think. You'd have to split taint checking from actual tainting, for starters. But worth thinking about.</p> Simon 2002-06-12T16:10:08+00:00 journal Grading hack <tt>lynx -dump |<br>perl -lane '$x=(2100-$F[5])/100;<br>print "$F[2] $F[1] ($F[4]) European grade: "<br>.($x&gt;0?"${x}k":(1-$x)."d") if $F[3] eq "Oxf";'</tt> Simon 2002-06-12T08:49:03+00:00 journal John Martyn <a href="">Grace and Danger</a> was recorded in 1979. It was released in late 1980.<p> Not because there were any problems with it, but because Chris Blackwell, the head of the record company, though it was too painful to release. You've not felt angst until you've heard "Baby, Please Come Home" or "Some People Are Crazy". </p><p> <b>Warning: Do not listen to this album alone.</b></p> Simon 2002-06-11T20:55:47+00:00 journal Sick sick sick <p>Idea of the day: JIT the bytecode produced by the regexp engine. Shouldn't actually be too hard. Produce a bunch of C functions which perform each node, keep everything in registers, and use C magic to build a buffer stringing the assembly code for each function together.</p> Simon 2002-06-11T12:34:04+00:00 journal Teaching Every night before I teach, I dread the morning. But then when I get into the class and start teaching, I love it. Weird. <p> Tomorrow morning, I'm teaching regular expressions in the OUCS public Perl course; anyone from the University can come along and be taught basic Perl. It's a six week course of three hours a week - to give you a clue about the pace of it, we spent three hours a couple of weeks ago just on arrays. We're talking absolute beginning programmers here. Still, it's good fun. </p><p> I spent the day writing the course; I'm pretty much ready, although I haven't written all the notes I need - I don't have anything on substitution, say, but I'm sufficiently prepared I can make it up on the hoof. Fun.</p> Simon 2002-06-10T17:24:45+00:00 journal I am a veritable module machine again! <code>Games::Goban</code> and <code>Apache::AxKit::Language::XSP::ObjectTaglib</code> uploaded! Simon 2002-06-10T16:14:44+00:00 journal Overkill A mailbox scanner:<blockquote><div><p> <tt>#!/usr/bin/perl<br>use strict;<br>use Mail::Util qw( read_mbox );<br>use Mail::Internet;<br>use Mail::Address;<br>use Time::Duration;<br>use Date::Manip qw( ParseDate UnixDate );<br>for (map { Mail::Internet-&gt;new($_) } read_mbox("/home/simon/mail/pending")) {<br>&nbsp; &nbsp; my $when = $_-&gt;get("Date");<br>&nbsp; &nbsp; my $who = (Mail::Address-&gt;parse($_-&gt;get("From")))[0];<br>&nbsp; &nbsp; $when = time - UnixDate(ParseDate($when), "%s");<br>&nbsp; &nbsp; print "Mail received ",ago($when), " from ",$who-&gt;phrase,"\n";<br>&nbsp; &nbsp; print "Subject: ", $_-&gt;get("Subject"),"\n";<br>}</tt></p></div> </blockquote><p>Fourteen lines, six Perl modules, to summarise a mailbox. What <i>was</i> I thinking?</p> Simon 2002-06-10T10:50:53+00:00 journal Christdot <a href="">Slashdot for Christians.</a> I have no idea what I think of this. Simon 2002-06-08T15:53:01+00:00 journal Dumb File Format Of The Day <a href="">Smart Game Format</a>. <p> Actually, it's reasonably sane on the whole - it uses s-expressions to represent variations, and it's trivial to parse. Indeed, it's what <code>Games::Goban</code> will speak natively. </p><p> But I couldn't work out why I was getting weird off-by-one errors in <i>some parts</i> of my display code; indeed, everything outside the upper-left quadrant of the board. Then I worked it out. </p><p> This supposedly for-machine-consumption file format uses a pair of characters from 'a' to 't' to represent co-ordinates on a 19x19 board. The more alert of you will notice that 't' is not the 19th letter of the alphabet, but the 20th. That's right - it actually skips over 'i'.</p><p> Working around this makes the code messy; I think I should ditch the idea of storing the native co-ordinates, which would have been very nice, and use numerical co-ordinates instead. Ho hum.</p> Simon 2002-06-08T15:31:24+00:00 journal