in reply to Multiple form selections in cgi

The param method, when called with no arguments, returns a list of the names of all the CGI parameters.

foreach ($cgi->param()) { if (/^year_\d+$/) { push(@years, $cgi->param($_)); } }

which can be rewritten as follows:

@years = map { $cgi->param($_) } grep { /^year_\d+$/ } $cgi->param();

Replies are listed 'Best First'.
Re^2: Multiple form selections in cgi
by punch_card_don (Curate) on Sep 26, 2005 at 19:09 UTC
    Thanks. This would definitely work, and fall within the definition of

    Or some variant that cycles through all form elements looking for anything named "year_x".

    For the sake of elegance, I'm wondering if there's not something else.

    Forget that fear of gravity,
    Get a little savagery in your life.

      Unfortunately the id attributes of your form elements do not get sent to your CGI scripts, only the names and values.

      One of the features (OK, probably the only feature) that I like about PHP is you can name form elements something like blah[3][2] and then PHP will automatically create an 2D array with that element's value at [3][2]. I wonder if there's a CPAN module for doing similar form parsing in Perl?