in reply to CGI.pm: $q->param can be an array. Can be a single value. How do you know which?

One small point of terminology, "param" _never_ returns an array. It returns a list. The difference can be important.

Here's some code that does what (I think) you want.

my %params; foreach (param) { $params{$_} = [ param($_) ]; $params{$_} = $params{$_}[0] if @{$params{$_}} == 1; }

You'll end up with a hash (%params) that contains a key/value pair for each parameter name. If the parameter is single-valued the value will contain that (single) value. If the parameter is multi-valued, then the value will be a reference to an anonymous array containing all of the values.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

  • Comment on Re: CGI.pm: $q->param can be an array. Can be a single value. How do you know which?
  • Download Code