Well, your main question is nice and easy, and nearly all that complexity can go. CGI.pm will return input parameters as an array if asked for them in array context, however many there are. So:

use CGI; my $input = new CGI; my @var = $input->param('var');

should work without your having to pad the form or check the browser type. tests with:

use CGI; use Data::Dumper; my $input = new CGI; my @var = $input->param('var'); print "Content-type:text/plain\n\n"; print Dumper \@var;

seem to confirm that it works. But anyway, if you _really_ want to load the input into a namespace (why?), you don't have to go through all those hoops to do it:

my $query = new CGI; $query->import_names('input');

will import the entire parameter set into an input:: namespace, and you can then just ask for @input::arrayparam to get values in array form. But you lose a lot of power this way: it's hard to iterate over the set of input parameters, for example. I would suggest using the object-oriented interface to CGI instead, if you can, and passing around the CGI object if necessary. It's safer, more flexible and more friendly to later development than this approach, which seems very vulnerable to me.

But i confess i'm slightly baffled by the javascript part - can't see what it's doing for you - so perhaps am up wrong tree entirely?


In reply to Re: CGI Ensure Array by thpfft
in thread CGI Ensure Array by SteveRoe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.