http://www.perlmonks.org?node_id=179527

dooberwah has asked for the wisdom of the Perl Monks concerning the following question: (cgi programming)

In PHP (yes, I've worked in it) you can have several inputs on a webpage enter as an array in your script. All you need to do is name them like an array: using a name, square brackets and a number (foo[1], foo[2], foo[3], etc.). Is there any Perl module/module function to do this sort of thing?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: Input arrays to CGI
by jeffa (Bishop) on Jul 04, 2002 at 21:59 UTC
    CGI.pm will handle this. All you need to do is request the multi-value parameter as a list:
    use strict; use CGI qw(param); use Data::Dumper; my @list = param('list'); print Dumper \@list;
    Run this on the command line like so:
    ./foo.pl 'list=foo&list=bar&list=baz&list=qux'
    
    and you should see the following:
    $VAR1 = [ 'foo', 'bar', 'baz', 'qux' ];
Re: Input arrays to CGI
by Anonymous Monk on Jul 08, 2004 at 11:11 UTC
    Are you posting in the right place? Check out Where should I post X? to know for sure. Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following: a, b, big, blockquote, br, caption, center, col, colgroup, dd, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, li, ol, p, pre, readmore, small, span, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul Snippets of code should be wrapped in <code> tags not
     tags. In fact, 
     tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible editor intervention).
    Want more info? What shortcuts can I use for linking to other information? or Writeup Formatting Tips are good places to start.