Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

RE: RE: Re: Easy way to run tests on many CGI params?

by ncw (Friar)
on Aug 31, 2000 at 11:35 UTC ( [id://30481]=note: print w/replies, xml ) Need Help??


in reply to RE: Re: Easy way to run tests on many CGI params?
in thread Easy way to run tests on many CGI params?

If you were worried about this you could collect the parameters like this :-
my $hash = {}; for ($cgi->param()) { push @{$hash->{$_}}, $cgi->param($_); }
However I find that 9 times out of 10 you want the simpler hash, so you can collect the data twice in a slightly more complicated way something like this :-
my $hash = {}; for ($cgi->param()) { push @{$hash->{list}->{$_}}, $cgi->param($_); $hash->{scalar}->{$_} = $hash->{list}->{$_}->[0]; }
You can then access most data with a simple $hash->{scalar}->{'whatever'} but for those cases when you cared about multiple entries you can do $hash->{list}->{'whatevers'}->1

I think the CGI module is fantastic, but I do find it much more convenient to have my data in a hash rather than have to call it from param() when I need it. For a CGI of any length then I'd certainly use one of another of the methods above.

Replies are listed 'Best First'.
RE: RE: RE: Re: Easy way to run tests on many CGI params?
by merlyn (Sage) on Aug 31, 2000 at 14:37 UTC
    If you want your data easily broken out so you don't have to call param, the easiest way is probably just to use the import_names call:
    IMPORTING ALL PARAMETERS INTO A NAMESPACE: $query->import_names('R'); This creates a series of variables in the 'R' namespace. For example, $R::foo, @R:foo. For keyword lists, a vari- able @R::keywords will appear. If no namespace is given, this method will assume 'Q'. WARNING: don't import any- thing into 'main'; this is a major security risk!!!!
    Then you still get both the single item $R::foo and the occasional list item @R::bar. And no code to cargo-cult-schlep around.

    -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found