in reply to cgi: Grabbing Multiple input values

Assuming you're using the CGI module (and you should probably be; search here for why), you can get an array with the selected values. From the CGI manpage:

FETCHING THE VALUE OR VALUES OF A SINGLE NAMED PARAMETER: @values = $query->param('foo'); -or- $value = $query->param('foo'); Pass the param() method a single argument to fetch the value of the na +med parameter. If the parameter is multivalued (e.g. from multiple selecti +ons in a scrolling list), you can ask to receive an array. Otherwise the meth +od will return a single value.

Replies are listed 'Best First'.
Re^2: cgi: Grabbing Multiple input values
by Anonymous Monk on Jan 17, 2017 at 14:31 UTC

    Update, since this was the first in a search for "perl cgi param multiple values."

    Newer versions of CGI.pm will generate a warning if you use

    my @vals = $q->param('input');
    Better to use
    my @vals = $q->multi_param('input');

    From man CGI: "Warning - calling param() in list context can lead to vulnerabilities if you do not sanitise user input as it is possible to inject other param keys and values into your code. This is why the multi_param() method exists, to make it clear that a list is being returned, note that param() can still be called in list context and will return a list for back compatibility."

    And "If you call param() in list context with an argument a warning will be raised by CGI.pm, you can disable this warning by setting $CGI::LIST_CONTEXT_WARN to 0 or by using the multi_param() method instead"