in reply to
Re: Unexpected CGI param behavior
in thread Unexpected CGI param behavior
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') );