Monday, 9 February 2009

Installing PHP, MySQL and Perl modules on Linux

Lately I've been doing quite a bit of work with Perl and I needed to count the number of characters in a string. Usually this is done with this command:
$len = length($string);
But what this actually does is count the number of bytes, so if you are using an encoding like UTF-8 it will not give the correct count of the letters in the string. I did a little search and discovered the existence of the Unicode::String module. I tried to follow the instructions to install it on Linux Ubuntu but both the usual and the manual method failed!

I discovered that you can use the Synaptic Package Manager to install Perl modules! If you do a search for "Unicode::String" in synaptic you can find the module and it installs so easily! So now the code is like:

#! /usr/bin/perl -w
use Unicode::String qw(utf8 latin1 utf16);

#... (some code to get the string from the file and stick it into $str)
$uStr = utf8($str);
print $uStr->length;

Another thing I was doing was messing about with the PHP module in Netbeans. They provide probably the best instructions on the Internet on how to install Apache, PHP and MySQL on Linux: http://www.netbeans.org/kb/docs/php/configure-php-environment-ubuntu.html

No comments:

Post a Comment