June 2006 Archives

You can probably figure out easily how to make a plural of a word in the English language, and when to put a or an as the indefinite article. However, it's not that easy when you need to do that dinamically on words provided by an user or coming from some other source. Also, you have no elegant way to automatically print something like this:

Your ranch contains no cows.
Your ranch contains 1 cow.
Your ranch contains 4 cows.

with a single print statement. Lingua::EN::Inflect provides all these features, so it allows to write proper English plurals even when you don't know the words you have to inflect. Just say:

use Lingua::EN::Inflect qw/:ALL/;

for my $n(0, 1, 4) {
    print 'Your ranch contains ' . NO( 'cow', $n ) . ".\n";

The output of this code is exactly the text shown above. Even though this is a very useful feature, Lingua::EN::Inflect offers many more utilities to work with plurals in the English language. Keep on reading to discover the gory details.

FIFA World Cup 2006


This is my first soccer-related blog post, as I've not been much interested in professional soccer for a few years. As you all know, there's the fucking World Cup now. England won it exactly 40 years ago, let's see if it happens again...

Bump: 2006-06-21 10:58:12 (was 2006-06-09 18:32:56)

Come tutti dovrebbero sapere, domenica 25 e lunedì 26 Giugno si terrà il referendum confermativo in merito ad alcune riforme costituzionali che il centrodestra aveva approvato durante il suo mandato. Vediamo di capire bene come bisogna votare.

Il quorum non è previsto per questo tipo di referendum, che sarà dunque valido a prescindere dalla percentuale dei votanti.

Spiegazione sintetica: vota , fai un favore alla Nazione liberandola dagli inutili parassiti, promuovendo il federalismo, e dando ad essa un ordinamento più moderno. Votando sì:

  • Si formalizzano i maggiori poteri del premier, che quindi sarà più responsabilizzato e dovrà dimostrare di essere una guida forte.
  • Si conferiscono a camera e senato ruoli diversi (la prima si occuperà di leggi di interesse nazionale, il secondo di leggi di interesse regionale). Al momento sono l'uno il doppione dell'altra.
  • Si riduce il numero di deputati e senatori, portando alla responsabilizzazione degli stessi, che - essendo in numero minore - saranno più visibili e quindi meno portati a scaldare la poltrona; ciò porterà anche al taglio di spese inutili.
  • Si riducono, nella magistratura, i rischi di conflitto di interesse e di politicizzazione.
  • Si attua la sospirata "svolta federale", definendo precise materie di competenza regionale ed altre di competenza nazionale.

Spiegazione lunga: clicca sul link sottostante (o continua a leggere se sei già nella pagina della storia).

I don't even know how many SQL statements I wrote in my programming life so far. Embedding the SQL into your code, whatever language you use, makes it less readable, uglier and - especially if the complex queries - particularly inelegant. Even when coding in a MVC fashion (which is highly recommended in some cases, like web applications) you end up to just moving the ugly code to the model part of your program, while removing it entirely would probably be the best choice. The problem is that you actually need to query the database somehow, so you can't remove the SQL code; however, you can put something else in place of SQL statements. Let's see what, from the point of view of a Perl programmer of course. ;-)

There are modules which allow SQL abstraction by generating SQL code from data structures. They let you use an arbitrary complex structure to build an arbitrary complex query without inserting any database-related code into your Perl program. Note that this is different from what ORMs - Object Relational Mappers - do: the latter abstract the SQL database into objects, while what I'm talking about abstracts the queries. However, a good ORM such as DBIx::Class provides query abstraction as well, usually by relying on one of the modules available on CPAN. You'll probably want to use an ORM, but that's not what I'm discussing here.

In this short article I'll cover SQL::Abstract, which is also the module DBIx::Class uses. It is fairly easy to get used to it to write simple queries, and with a bit of thought also the complex queries can factored into Perl data structures. For instance if you have:

my $query = "SELECT users.name, users.phone, users.email
    FROM users
    WHERE users.id = 1 OR users.id = 2
    ORDER BY id
my $sth = $dbh->prepare($query) or die $dbh->errstr;
$sth->execute() or die $dbh->errstr;

You can write this instead with SQL::Abstract:

my $sql = SQL::Abstract->new();

my ($query, @bind) = $sql->select(
    [ 'name', 'phone', 'email' ],
    { id => [ 1, 2 ] },
    [ 'id' ],
my $sth = $dbh->prepare($query) or die $dbh->errstr;
$sth->execute(@bind) or die $dbh->errstr;

You might protest that the code is longer, and it actually is a bit (even though code formatting contributes to that). It's however much clearer: there's no extra-Perl code around field names and values, and you can easily understand what the query does at first sight. The select method accepts four parameters: the name of the table on which you want to work, the fields you want to retrieve, the where clause, and the optional ordering of the results. You get, as return values, a string containing the query, and the array of the bound values which you need to use when calling execute().

The Da Vinci Code

| No Comments

Rating: 8

I was a bit skeptical about this movie, but I was curious beacause of the talk (some would even say scandal) that is continuing to rise around it. Demonized by the Church, acclaimed by the fans of the book, at first it seemed that The Da Vinci Code was not only a masterpiece, but a revelation for all the Christian world. However, many people who saw it are commented "oh, it ain't worth", "don't watch it, it's really bad", "the book is way better", "both the book and the movie suck", etc...

Before going any further, let me say that I did not read the book.

The movie starts with a murder in Paris. Soon after the discovery of the body, it's quite clear that it's not a simple murder but that there's something bigger behind; the size of this "something" grows as the movie goes on, until the viewer understands it's an hidden truth which can shake the Christian Church from the roots (by the way, there are chances it is really true). The first part of the film is an excellent crime thriller, then it slowly changes by mixing in genres such as thriller, adventure, and even comedy. As the American symbologist Robert Langdon and the French policewoman Sophie Neveu continue their quest towards the truth, the situations, places and characters would perfectly fit in an Indiana Jones movie. And this, besides the damn good plot, is what keeps the movie entertaining until the last scene (which shows up nearly 150 minutes after the murder).

There's no need to comment on Tom Hanks' brilliant performance in the role of Robert Langdon. Audrey Tatou, the fascinating Amelie at her first Hollywood experience, deserves a praise for the excellent starring in Sophie Neveu character. Besides the main actors, my favourite is Ian McKellen (in the role of Sir Leigh Teabing): despite being a controversial character, he's so fun with his all-British style and humor.

The Da Vinci Code is likely to become one of the most commercially successful movies of all time. Is that deserved? Well, I think so. It's not a masterpiece, but that means nothing (were Titanic and Harry Potter masterpieces?). Ron Howard's work will not shake the ground under you feet, but it is very entertaining: don't miss it.

About this Archive

This page is an archive of entries from June 2006 listed from newest to oldest.

May 2006 is the previous archive.

July 2006 is the next archive.

Find recent content on the main index or look in the archives to find all content.



OpenID accepted here Learn more about OpenID
Powered by Movable Type 5.14-en