Thursday, 6 September 2007

French Perl Workshop 2007

I signed up for the French Perl Workshop 2007 in Lyon, and I proposed two talks: one on the new shiny stuff in Perl 5.10, and a smaller one on encoding::source, one of my scary modules. (I had this last idea while giving an impromptu presentation of encoding::source at the latest Amsterdam.pm meeting last Tuesday.) By popular demand, my presentations will be in French. See you there.

(Now I have to write slides...)

Wednesday, 5 September 2007

Blue versus Pink

Baignade autorisée Found via slashdot, an article on Bad Science criticizing a research in evolutionary psychology about why boys prefer blue, and girls pink. The author says, and rightly:

The “girls preferring pink” thing is not set in stone, and in fact there are good reasons to suspect it is culturally determined.

And then he gives examples. But if I may add another remark to his rant: it turns out that the categories of blue and pink are also culturally determined. Actually, the colour blue didn't even exist as a separate entity before the Middle Ages. Ancient Greek, for example, does not have a word for blue, and Homer speaks about the wine-coloured sea.

I think that the study of colours and their perception is more a subject for historians than for biologists or physicists. On this subject, one of the best books I've read is Blue, the History of a Color, by Michel Pastoureau, in which the last chapter briefly talks about the very recent (and very occidental) association of blue and pink to boys and girls, respectively.

Tuesday, 28 August 2007

On Gravitas

Gravitas is a novel by S. Christopher, centered around a character named Ben, and his evolution at the edge of his thirties. In a few words, Ben lives in a medium-sized American city (that could be Portland, for instance); he's a senior programmer in a small software company; he has a geeky housemate.

The novel has no other real purpose than to depict Ben's life and mind. That has shaped the narrative style, which proceeds by an accumulation of scenes, not necessarily in chronological order, rather than by a well-formed, developing plot. Ben is, by many criteria, successful, but by other traits, he's not strictly in tune with his environment: sometimes he appears to shift by a half-tone, maybe more, leading him to be a spectator of himself (and others). The love (and pain) that a girl will inflict on him will force him out of his shell, at least for a period, and he will live this event as a small, strange trauma, maybe the first of his life, not counting his own birth.

Minor themes are recurrent through the book, indicating that it's better constructed than it would be obvious at a first glance.

One of those themes is the disappearance -- of days, people, words, that seem to slip through Ben's memory, as if reality wouldn't let itself be captured easily as a mind representation, by someone who is reluctant to engage in it fully.

Another theme might be abstraction. I don't find a better word for that capacity -- or defect -- that some people have, to perceive things through an emotionless prism, like one would look at a piece of software, including oneself.

The author uses a dense, rich form of English, full of images. This prolixity suits well the introspective nature of the book.

I enjoyed Gravitas. On an ideal shelf, it would be between P.K.Dick's non-sci-fi novels and Meredith's Egoist.

Monday, 6 August 2007

mysql command-line tricks

I use the MySQL shell a lot. A couple of tricks can make it more usable:

First, prompt customisation. I work with lots of different databases on different hosts. So, I customised my prompt via an environment variable:

export MYSQL_PS1="\\d@\\h> "

This makes mysql display the database name and the hostname instead of the fixed string "mysql":
$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 143955 to server version: 5.0.27-standard-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

test@counterfly>

Secondly, readline configuration. When editing long SQL statements, I prefer to use vi-like keybindings. That can be selected by adding the following lines to your ~/.inputrc file:
$if Mysql
set keymap vi
set editing-mode vi
$endif

You can then navigate history and edit like like you would do (almost) in vi. See your readline manual for more details.

Friday, 13 July 2007

$* replacement

So, the special variable $* has been removed from perl 5.10, after having been deprecated for years. For those who don't remember Perl4-style programming, $* was used to enable multi-line matching in regular expressions. In Perl 5, the preferred way to do it is to use the more flexible regexp flag /m.

I removed that poor old variable not because I like removing old things, but because it was standing in the way of a bug I wanted to fix (bug #22354). Anyway. Apparently there is still out there some old Perl code that fears not using $*. And notably ghc's evil mangler, which broke with perl 5.9.5.

But Audrey Tang (who else?) found an elegant way to emulate $* = 1, in a characteristic perl-zen manner. Here's how: the current evil mangler contains this simple line of code, in a BEGIN block:

require overload; overload::constant( qr => sub { "(?m:$_[1])" } );

Wednesday, 11 July 2007

Saving GNOME settings

Here's a small tip I got from GNOME expert Pascal Terjan, and that I'm copying here because I don't trust my memory:

Want to inspect the settings of some GNOME application? Use gconf-editor.

Want to copy the settings of some GNOME app (like, say, metacity) from one desktop to another? Use the command-line tool gconftool, specifically the options --dump and --load. (The paths you need to feed to gconftool can be retrieved via gconf-editor.)

Tuesday, 10 July 2007

Munin plugin for ping response time

My ADSL router (a freebox) shows a recent tendency to desynchronize itself. That's annoying, even it that only lasts a few minutes from time to time. Maybe a cable needs to be replaced (advice?). So, I quickly hacked this plugin for Munin, an excellent system monitoring package:


#!/usr/bin/perl -wT

use strict;

our @HOSTS = qw(free.fr);
if (@ARGV && $ARGV[0] eq 'config') {
print <<CONFIG;
graph_title Ping response time
graph_vlabel time (ms)
graph_args --base 1000 -l 0
graph_scale no
graph_category network
CONFIG
for my $host (@HOSTS) {
my $name = $host;
$name =~ tr/./_/;
print "$name.label $host\n";
}
}
else {
@ENV{qw(PATH)} = qw(/bin);
for my $host (@HOSTS) {
my $name = $host;
$name =~ tr/./_/;
my @ping = qx(/bin/ping -nc1 $host 2>/dev/null);
my $times = $ping[-1];
my $val = '';
if ($times =~ m{^rtt min/avg/max/mdev = ([\d.]+)}) {
$val = $1;
}
print "$name.value $val\n";
}
}

Feel free to adapt/improve. This code is of course released under whatever license Munin is released under (I didn't bother to check.)

Monday, 9 July 2007

Perl 5.9.5

I've released Perl 5.9.5 on saturday. Get it while it's hot. Get the official announcement as well.

Wednesday, 4 July 2007

Sub::Current

I've released another new heavily magic Perl module on CPAN, this time scratching an itch of Yves Orton. It's called Sub::Current and allows you to get a reference to the currently executing subroutine.

At first I wanted to use a tied scalar instead of a function to get this reference; however, due to the way parameter passing is implemented in Perl, that's not easily possible: the tied variable (let's call it ${^ROUTINE}) is FETCHed at the innermost scope, so this won't work:


sub foo {
# here ${^ROUTINE} points to bar(), not to foo() !
bar( ${^ROUTINE} );
}

I think that could be done by tweaking some of the ck_ functions that are used to optimize Perl's internal optree during the compilation phase. I know that some people are not afraid to do this, but I feel that this would be a rather fragile solution, for only a little bit of syntactic sugar.