It's quite common (and useful) to have multiple values associated with one name. These aren't keys in the same sense that unique identifiers are in a database. Considering the following:

You're creating a Web page where people can sign up for mailing lists on their favorite sports. You have the following HTML:

<input type="checkbox" name="football" value="football"> <input type="checkbox" name="soccer" value="soccer"> <input type="checkbox" name="tiddly winks" value="tiddly winks">
In your code, you check for each of those values and subscribe the person to the mailing list appropriately. However, as time goes on, your site becomes wildly popular and you are looking at your IPO. You include more and more sports, but your scripts are becoming difficult to maintain because you have to test for each and every sport individually. Instead, change your HTML to the following:
<input type="checkbox" name="sports" value="football"> <input type="checkbox" name="sports" value="soccer"> <input type="checkbox" name="sports" value="tiddly winks">
Your query string will resemble the following (if they check both football and tiddly winks):
sports=football&sports=tiddly%20winks
In your script, you'd have something like the following:
my @sports = $q->param('sports'); foreach my $sport ( @sports ) { # subscribe them to the list }
That is much simpler than having separate names for each sports. Programmatically, it's the way to go.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to (Ovid - why we allow multiple values for a name in a query string) by Ovid
in thread Pushing w/ an associative array? by Anonymous Monk

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.