in reply to Using CGI param method

CGI will have already read the input. You should simply use something like:
#!/usr/bin/perl -Tw use strict; use CGI; our $q = CGI->new(); our %FORM; sub parse_form { # Get the input foreach my $p ($q->param()) { $FORM{$p}=$q->param($p); } } parse_form(); print "Content-type: text/plain\n\n"; while(my($k,$v)=each(%FORM)) { print "$k: $v\n"; }

Updated: Fix error (shouldn't use both :standard and create a CGI object) and add enough code to make this a complete, testable program.

Replies are listed 'Best First'.
Re: Re: Using CGI param method
by Belgarion (Chaplain) on Apr 20, 2004 at 17:03 UTC

    Is there a particular reason to use: use CGI? qw(:standard); and then create the CGI object? By creating the CGI object you already have access to all the methods normally exported by :standard. Is there something I'm missing here?

    The only explanation I can guess at would be a mod_perl situation where you wanted to preload as much of the CGI module as possible before the webserver forked.

    Thank you for any insight you can provide.

      No, I just cut-n-pasted the OP's code and forgot to remove that. For mod_perl you'd use the -compile pragma to preload and pre-compile.
Re: Re: Using CGI param method
by TilRMan (Friar) on Apr 21, 2004 at 05:24 UTC

    It's even easier than that! CGI's Vars returns the very hash you're looking for.

    #!/usr/bin/perl -wT use strict; use CGI qw( header Vars ); my %FORM = Vars(); ### Bingo! print header( 'text/plain' ); $\ = "\r\n"; use Data::Dumper; print Dumper(\%FORM);
Re: Re: Using CGI param method
by Anonymous Monk on Apr 20, 2004 at 17:43 UTC
    Thanks I tried just exactly as you suggested and it doesnt work. Please advise if there is anything I can do to make this work?
      It works for me, so you'll need to post a bit more information about what you're doing, what you expect to happen, and what's happening instead.
        Thanks it now works:
        use strict; use CGI qw(:standard); sub parse_form { foreach $p (param()) { $FORM{$p}= param($p); } }
        Just trying to clarify what the use CGI qw(:standard) module is doing? It already assigned an object for param so I can reference it above? I am just curious to what is going on in the above area??