Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Thursday January 02, 2003
03:51 AM

Multiple CGI objects

[ #9712 ]

I got out of CGI programming a long time ago, but I have a new use for query strings. I could probably do this with a different module that is not as heavyweight as, but I would have to think extra to do that.

I remember several discussions a long time ago, in a newsgroup far, far away, about why anyone would ever need more than one CGI object in a program at a time. Well, in the program I needed today, I had nine of them. Yes, that object-oriented interface is there for a reason.

But, since I really just want the query string, I combine my latest, favorite technique with an older favorite technique---the do {} statement.
I scope the CGI object to the do block and extract the query string at the end of the block, making it the return value that shows up in $query. Everything is wrapped up in a nice, little package.

my $query = do {
    my $cgi = CGI->new();
    $cgi->param( 'TopOne',    1       );
    $cgi->param( 'userid',   'comdog' );
    $cgi->param( 'password', 'nope!'  );
    $cgi->param( 'Attempt',   0       );