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.

Monday, 25 June 2007

Do you dream in colour?

Squares
Do you dream in color? asks Mark-Jason Dominus. Interesting question, on which I've already some thoughts.

I'm colour-blind. I see some colours, but the words that are used to describe colours are for me largely arbitrary. Why use two different words, like, green and orange, for the same colour? A consequence of that is a difficulty to verbalize colours, which in turn makes it difficult for me to remember the colour of an object, if nobody told me what word to use to describe it. Without a proper vocabulary to classify them in my brain, I can't remember or percieve fully the colours.

So it shouldn't be a surprise that I dream "in black and white": or, more accurately, that I can't name and remember the colours of the objects that appear in my mind during dreams. Colours are an irrelevant part of my Weltanschauüng.

However, from time to time, I make a dream about a colour. Those are in general very simple dreams, focused on a single object; nothing happens; sometimes I only dream about a colour without an object. (Robert Louis Stevenson, in A Chapter on Dreams, says that he sometimes dreams about a particularly horrible and uncanny hue of brown.) And usually that colour is mauve, or the idea I have about what mauve should look like: a mix between red and blue, which does not exist for me in the real world.

I'm not sure how to explain this. Probably my brain is playing tricks to iself (that is, to me): my eyes are not able to send the signal mauve to the brain, but the brain circuitry is intact and is able to perceive mauve once the eyes are out of the loop. However, that new colour is so strange that it soon overrides all other aspects of the dream it appeared in. I don't have any other explanation (short of the Platonician thesis, that learning is remembering.)

Wednesday, 20 June 2007

encoding::source

I'm happy to announce to the unsuspecting world that I've released to the CPAN a new Perl module, encoding::source. Like I say in the docs, this is like the encoding pragma, but done right. In other words, it allows you to change, on a per-file or per-block basis, the encoding of the string literals in your programs.

That's probably some of the scariest Perl code I've written. Note that it won't run on any released perl. You'll nead bleadperl (or the upcoming 5.9.5) for that. That's because it uses the new support for user-defined lexical pragmas.

Monday, 18 June 2007

Best Doctor quote ever

We're at the end of the universe, right at the edge of knowledge itself, and you're busy... blogging!

The Doctor, in Utopia

Thursday, 14 June 2007

On Olympia




Edouard Manet, while young, once copied Titian's Venus of Urbino, for practice. Later, when he produced one of his most famous and avant-garde paintings, Olympia, he was reminiscent of the old Venetian master: for he based his programmatic female nude on Titian's classical Renaissance Venus, but carefully inverted all the details.

The pose of the nude woman, lying on a bed, looking at the spectator, is the same on the two paintings. However, the Venus has a crouching puppy at her feet, while Olympia has there a cat standing up. Titian's scene has an open, bright background; Manet closed it with a dark curtain. Maidservants are seen on both paintings: Venus has two pale-skinned servants, seen in the background, from behind; the servant of Olympia is dark-skinned, faces the spectator, and is placed in the foreground. The Venus holds flowers; Olympia is about to receive flowers held by her servant. The Venus is in a diurn haze that suits the goddesses; Olympia is in a crude light, evoking a closed place rather than the openness of a Venetian palace.

As I see it, all those inversions are signs employed by Manet to indicate the subject of his painting: down with gods and goddesses, paint the reality. But they also indicate that Manet was seeing himself as part of the tradition, and that he wanted his works to be inserted in a dialogue with the masterpieces of the past. I'd rather be careful not to say too many things about Olympia, since the interpretation of this complex painting is quite difficult, that I will probably change my mind about it a few dozen times in the future, and that I haven't even seen it for real, although I live near the Orsay Museum. Anyway, those inversions are worth being noted.

(On a side note, I remember that Giorgio Vasari reports, in his Lives of Artists, that Michelangelo told him that Titian was a great painter, but that he couldn't draw. The same reproach was made, until late, to Manet...)