Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Getting hash of CGI variables

by matthewb (Curate)
on Jan 22, 2004 at 20:29 UTC ( #323311=note: print w/replies, xml ) Need Help??


in reply to Getting hash of CGI variables

The section of the documentation to CGI.pm that you are looking at demonstrates the capture of both single parameters and groups of parameters with a common name. This is explained in the two paragraphs that follow the example.

Assuming that you have passed a parameter named `address' to your script you may access it in a number of ways, commonly:
my $value = $q->param('address');
...where $q is your CGI object. In the event that you want to put all the form parameters into a hash using the Vars method, you may access the value as follows:
my $v = $q->Vars; my $value = $v->{'address'};
In both of these examples, the only significance of the word `address' is that it was the name of the parameter passed by the referring form (or otherwise for the purpose of demonstration).

The line with the split illustrates how, having used the Vars method, one might separate a list of values with a common parameter name into an array. This may, however, be done in the following, more natural way:
my @array_of_values = $q->param('multi_values');
...where `multi_values' is, perhaps, the name of a bunch of checkboxes in the referring form.

MB

Replies are listed 'Best First'.
Re: Re: Getting hash of CGI variables
by Lori713 (Pilgrim) on Jan 22, 2004 at 20:52 UTC
    Thanks for the clarification and explanation. I appreciate your taking the time to explain what's going on so I can better use what I see.

    You have touched on one area that gives me the most heartburn... I don't know when examples are literal or placeholders.

    For instance, I now understand that "foo" and "bar" are what I think of as placeholders for the "real stuff" but I don't recognize things in some examples (like the word 'address') as something I need to replace with a real item. I'm hoping this is something that experience will teach me along the way. Then again, it may be the way I learn things... I learn by replicating what I see, and then tweaking the <bleep> out of it until I fully understand what the snippet does. Again, thanks!

    Lori

      I don't know when examples are literal or placeholders.

      This is slightly offtopic, but I just thought I might give some general advice. Most of the time, the things that are "placeholders" are either (1) variables or (2) strings. Exceptions should be pretty obvious, but if in doubt you can always simply play around with the example.

      One thing to be careful of, though, is when you see the same "placeholder" used more than once. If there are two instances of $foo in a snippet, you can usually change them to whatever you want, but just make sure you change them both to the same thing. Hopefully this too is obvious, but sometimes what's obvious to one is not to another. =^)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://323311]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2020-09-22 17:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (129 votes). Check out past polls.

    Notices?