My Problem With Perl

I’ve becoming increasingly frustrated with Perl.Every time I start a new project, I face the same dilemma: If this project will need to talk HTTP, or parse XML, or maniplate URIs, then Perl is not the best choice, since it doesn’t include modules to do this in its standard library. The first thing I do after I install Perl on a machine is install the LWP, XML::Parser, and URI modules, and each of these has a slew of dependencies (like HTML::Parser and expat). (ActiveState has done a great job with ActivePerl: They include LWP, URI, and XML::Parser with the distribution.) I find myself turning to python, ruby, or PHP quite often these days, since those languages don’t have this deficiency.

Having to get basic things from CPAN for every project is quite frustrating, especially when I’m installing scripts on a machine that I do not control. For example, I recently wrote a script that needed to run on a fairly stock Mac OS X machine, to which I didn’t have administrative access. The script was in Perl, and I could not install any modules on the machine¹; I had to resort to:

my $data = `curl $url`;

to make HTTP requests. Not the end of the world, of course, and it could have been much worse. But if I had needed access to the header information, for example, my code balloons:

my $data = `curl -D- $url`;
my ($headers, $body) = split /\r\n\r\n/, $data, 2;
my %headers;
for my $line (split /\r\n/, $headers) {
    chomp $line;
    if ($line =~ m!^HTTP/!) {
        $headers{'Status'} = $line;
    else {
        my ($name, $value) = split /:s*/, $line;
        $headers{ $name } = $value;

and so on. It can get very ugly very quickly. Compare this with:

use LWP::Simple qw($ua);

my $res = $ua->get($url);
my $body = $res->body;
# get a header with $res->header($field)

My version is OK, but as soon as I need to parse an Accept header, I’m sunk. And, of course, if the machine didn’t have curl on it, I’d be in even bigger trouble.

Also, while I’m complaining, why is Perl the only language whose XML parser has an external dependency? Every other language has a native implementation of an XML parser that doesn’t require libexpat to be installed. This is another source of frustration for me. And again, ActiveState does it right by including it with ActivePerl.

  1. I know about putting modules in a non-standard location; I was asked specifically not to install other modules on this machine. []
About these ads

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: