Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Unexpected CGI param behavior

by cLive ;-) (Prior)
on Jun 24, 2008 at 20:35 UTC ( #693824=note: print w/replies, xml ) Need Help??

in reply to Unexpected CGI param behavior

Hmmm. I guess my beef is with the fact that param() is another victim of "wantarray madness".

Ah well, live, learn and write explicit code to solve the issue...

Replies are listed 'Best First'.
Re^2: Unexpected CGI param behavior
by ikegami (Pope) on Jun 24, 2008 at 20:39 UTC

    You have it backwards, as far as I'm concerned. Your snippet would still fail without wantarray. Without wantarray, my $scalar = $cgi->param('foo'); would *also* fail.

    That's the case for every function that returns a list. Perl can't return a list in scalar context, so param must necessarily return something different in scalar context. wantarray simply helps return a meaningful value instead of junk.

    Since param returns a list, feel free to always call param in list context if you want to avoid the issue.

    my @values = $cgi->param('foo'); my ($first_value) = $cgi->param('foo'); my $first_value = ( $cgi->param('foo') )[0];

      "would *also* fail" - um, no it wouldn't, because it explicitly returns a scalar undef. I've tested it.

      Of course, what it would do is change an array assignment:

      # from @array=(); # to: @array=(undef);

      Which would be an unacceptable change to existing behavior (exists $array[0] value would change from empty string to 1).

        Not that situation, the situation where the field is present.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://693824]
LanX Finally, there is a certain order or choreography to the greetings, which Kornhauser-Duda appears to have been following. First, the two heads of state shake hands, while the two first ladies do the same
[LanX]: FAKE NEWS , erix, so sad! Fired!

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2018-03-22 20:16 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (286 votes). Check out past polls.