perl and unicode

20 September 2009

I have just found an interesting entry about perl and unicode:

http://perlgeek.de/en/article/encodings-and-unicode

Apart of the typical recommendation of using :encoding(UTF-8) as an input layer, it has a script for finding out which is the encoding of your shell:

#!/usr/bin/perl
#!/usr/bin/perl
use warnings;
use strict;
use Encode;

my @charsets = qw(utf-8 latin1 iso-8859-15 utf-16);

# some non-ASCII codepoints:
my $test = 'Ue: ' . chr(220) .'; Euro: '. chr(8364) . "\n";

for (@charsets){
    print "$_: " . encode($_, $test);
}

Also, this entry explain how some perl function are expecting text string or ‘Codepoints’ instead of binary data and explains how to decode the strings properly to pass them to this functions.

This other entry also explain how to avoid the ‘wide character in print’ warning ahinea.com/en/tech/perl-unicode-struggle.html, and here there is an explanation of the difference between UTF-8 and utf8 (jeremy.zawodny.com/blog/archives/010546.html).

If you want to read more about encoding:

Finally al link to perlmonks where it is explained why the pragma :utf8 is insecure and you should use :encoding(UTF-8)
www.perlmonks.org/index.pl?node_id=731943

perl one-liner: print filenames with content matched

17 September 2009

If you want to know which files contains a specific text string you can do:

perl -nle '/find this/ and print $ARGV and close ARGV' file1 file2 .....
  • $ARGV contains the name of each file.
  • ARGV is the filehandle for $ARGV.
  • This one-liner searches each line (-n option) for a match (/xxx/) and when it happens (and) prints the file name and closes the filehandle to pass to search the next file.

This one-liner is very useful when  combined with xargs.


Frozen Bubble

12 September 2009

Pero mira que bien! acabo de enterarme que Frozen Bubble (juego adictivo donde los haya) ha sido creado con perl_sdl.

Si es que Perl es el Emacs de los lenguajes de programación 😉


Por que debes usar Perl 5.10.x?

11 September 2009

Por que es un salto cualitativo en la modernidad de Perl. Es un paso mas hacia Perl 6 y aunque algunas de sus funcionalidades se pueden conseguir en Perl 5.8 con diferentes modulos, usar Perl 5.10 es una declaración de intenciones. Significa que estas actualizado y te preocupas por las herramientas que usas.

Usar perl 5.10 y sus nuevas funcionalidades es una gran ayuda en tu estilo de programación, aunque solo sea por usar ‘say’ y los nuevos ‘given/when’ y ‘smart_match’.

Usar perl 5.10 no es sólo usar perl 5.10 sino que debe implicar también usar los nuevos paradigmas de programación y las nuevas herramientas disponibles en Perl como Perl::Critic, Moose, DBIx::Class, Catalyst, Devel::NYTProf, etc


Ya está disponible perl 5.10.1!!!

11 September 2009

Por fin ya está disponible perl 5.10.1. Esta nueva versión soluciona varios problemas de la version 5.10.0, pero también introduce ciertas incompatibilidades como por ejemplo la estructura de control given/when o el operador smart match.

Perl 5.10.1 mejora el uso de UTF8, pero aun no se hasta que punto Perl es capaz de manejarse bien con UTF8 sin hacerse un lío. Ya lo iremos viendo.

Si aún no estas usando perl 5.10.x aprovecha e instalalo. Perl 5.10 incorpora muchas novedades frente al 5.8 que ya tiene sus añitos. Las ventajas de perl 5.10 (‘perl moderno’)  son bastantes y las comentaré en una próxima entrada.

Los destalles de los cambios se pueden ver en perldelta, y se puede instalar desde CPAN

Cómo instalarlo en tu HOME: http://gugod.org/2009/08/install-perl-to-home.html