http://qs321.pair.com?node_id=94303

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm new to Perl and I need help with something I'm sure is simple for you veterans. I'm playing with CGI.pm and I can't figure out how to grab all the fieldnames and values off a form at once. I can get at them individually with $q->param('field') but there are over 25 fields and I want to get them all at once.

Edited 2001/07/07 by Ovid

Replies are listed 'Best First'.
Re: CGI
by PrakashK (Pilgrim) on Jul 06, 2001 at 02:06 UTC
    From the documentation of CGI:
    FETCHING THE NAMES OF ALL THE PARAMETERS PASSED TO YOUR SCRIPT: @names = $query->param; .... FETCHING THE PARAMETER LIST AS A HASH: $params = $q->Vars; print $params->{'address'}; @foo = split("\0",$params->{'foo'}); %params = $q->Vars;
    /prakash
Re: CGI
by tachyon (Chancellor) on Jul 06, 2001 at 02:04 UTC

    Rather than just give you the answer could I direct you to this tutorial I wrote CGI Help Guide. In it you will find a link to CGI.pm If you follow this link you will get to the official CGI.pm documentation where you will find your question answered under the heading "Fetching The Names Of All The Parameters Passed To Your Script..."

    You may find both the tutorial and the CGI.pm documentation helpful.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: CGI
by Maestro_007 (Hermit) on Jul 06, 2001 at 02:13 UTC
    If you use param in a list context with no arguments, it will return "the parameter names as a list" (according to this node),

    @list = $q->param();

    This node is a part of the standard distribution of Perl. Also read it by typing perldoc CGI at the prompt.

    There are literally hundreds of documents within a very close reach of this web site that can answer questions like that. I recommend to anyone who is new to Perl that they first familiarize themself with these documents. It may seem daunding at first, but once you get the hang of it, it's much more rewarding to find the answers on your own.

Re: How can I grab all CGI variables at once? (was: CGI)
by converter (Priest) on Jul 06, 2001 at 02:12 UTC

    Look at the "FETCHING THE PARAMETER LIST AS A HASH" section in the CGI manpage for details on the use of &CGI::Vars, which returns the entire list of parameters for assignment to a hash.

    Note that this section includes the warning: "When using this, the thing you must watch out for are multivalued CGI parameters."