Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Unexpected CGI param behavior

by pc88mxer (Vicar)
on Jun 24, 2008 at 00:47 UTC ( #693640=note: print w/ replies, xml ) Need Help??


in reply to Unexpected CGI param behavior

I think CGI implements this behavior so that param() can support both scalar and list context. In list context it returns all the values for a parameter and in scalar context it just returns the first value.

If it returned undef for unknown parameters, then this wouldn't work:

my @vals = $q->param('...'); print Dumper(\@vals); # would print [ undef ] not [ ]
That is, @vals would not be the empty list but a list containing undef.

A work-around is to use scalar:

my $var = { first => scalar $q->param('first'), second => scalar $q->param('second'), };


Comment on Re: Unexpected CGI param behavior
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2015-07-08 08:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (97 votes), past polls