Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Input arrays to CGI

( #179527=categorized question: print w/ replies, xml ) Need Help??
Contributed by dooberwah on Jul 04, 2002 at 19:48 UTC
Q&A  > CGI programming


Description:

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?

Answer: Input arrays to CGI
contributed by jeffa

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' ];
Answer: Input arrays to CGI
contributed by Anonymous Monk

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. 


Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (10)
    As of 2015-07-28 22:58 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (260 votes), past polls