jducoeur: (Default)
jducoeur ([personal profile] jducoeur) wrote2006-11-25 07:13 pm
Entry tags:

I hate Perl. Hate it, hate it, hate it...

Okay, all of you Perl aficionados who keep telling me what a nice language it is. I have a question for you. I'm trying to write a dirt-simple program to parse an input form using the standard CGI library on Unix. My code looks something like this:


use CGI qw(:standard) ;

$query = new CGI;

my $age = $query->param('age');
my $params = $query->Vars;
my $age2 = $params->{'age'};
print $query->Dump();


Why, prithee tell, do the first two versions (both taken directly from the CGI documentation) keep insisting that $age and $age2 are empty strings, despite the dump quite happily showing that the age parameter is being passed in as expected? This damned language is so opaque (and the documentation so miserable) I'm at a dead end even trying to figure out where the data is hiding...
mneme: (Default)

[personal profile] mneme 2006-11-27 06:32 pm (UTC)(link)
Depends on what was going on -- was it mixing get and post, frex? CGI.pm will happily parse both get and post -- but on a post request, it will only make the post options available -- the query string options (if also existent -- usually because they're in the form action) will be parsed but not made accessable unless requested. Not sure what else would generate the behavior described.

Perl is actually a remarkably elegant language -- for one that's as big as it is. (that said, there's a lot of accumulated cruft, some of which isn't really as useful as originally intended -- like the mutating funny characters on the beginnings of variables, and the related differences in the syntax for accessing a thing and for accessing a reference to the very same thing. Much of this will change in perl 6).

But CGI.pm is a bloated and over-ambitious tool, and one I'd not normally recommend using -- you're better off using a smaller CGI library that doesn't try to also handle HTML creation -- or just jump to mod perl, depending on your platform.
mneme: (Default)

[personal profile] mneme 2006-11-28 06:45 pm (UTC)(link)
CGI::Lite is much better. You might also want to try out CGI::Minimal, which looks pretty good on a first blush.