jducoeur: (Default)
[personal profile] jducoeur
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...

(no subject)

Date: 2006-11-26 01:09 am (UTC)
From: [identity profile] tangerinpenguin.livejournal.com
This is just speculation since I don't use that particular library much, but since you're using the object-oriented API rather than the functional shorthand, have you tried leaving off the :standard keyword to the use declaration?

show your form please

Date: 2006-11-26 01:54 am (UTC)
From: [identity profile] livemerlyn.livejournal.com
Without the whole picture, we'd only be guessing.

(no subject)

Date: 2006-11-26 02:06 am (UTC)
From: [identity profile] crschmidt.livejournal.com
So, I have this:

#!/usr/bin/perl

use CGI qw(:standard);
$q = new CGI;
print "Content-Type: text/plain\r\n\r\n"; 

print $q->param('age');


then:
http://crschmidt.net/code.cgi?age=1

works.

So, it sounds like your setup might be broken?

(no subject)

Date: 2006-11-26 04:06 am (UTC)
From: [identity profile] crschmidt.livejournal.com
Hard to know without seeing how your form was broken, and what the HTML behind the Dump was producing. (For example, an extra < in a variable might not be obvious in an HTML form, because it gets eaten by something, or something of that nature.)

In any case, sounds like you got it sorted.

(no subject)

Date: 2006-11-27 06:32 pm (UTC)
mneme: (Default)
From: [personal profile] mneme
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.

(no subject)

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

Profile

jducoeur: (Default)
jducoeur

June 2025

S M T W T F S
12 34567
891011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags