Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

How can I grab all CGI variables at once? (was: CGI)

by Anonymous Monk
on Jul 06, 2001 at 01:55 UTC ( #94303=perlquestion: print w/replies, xml ) Need Help??

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 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'.
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;
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 If you follow this link you will get to the official 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 documentation helpful.




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."

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://94303]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2022-05-28 15:57 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (99 votes). Check out past polls.