If you are only dealing with a single CGI parameter at a time, (i.e., are calling CGI::param with an argument), then the following snippet from 'perldoc CGI' is relevant:


FETCHING THE VALUE OR VALUES OF A SINGLE NAMED PARAMETER:

@values = $query->param('foo'); -or- $value = $query->param('foo');
Pass the param() method a single argument to fetch the value of the named parameter. If the parameter is multi- valued (e.g. from multiple selections in a scrolling list), you can ask to receive an array. Otherwise the method will return a single value.

Note that this means that if you call $query->param('GS1') in a scalar context, it will return a single value, regardless of how many values were set in the form.

On the other hand, if you obtain all your parameters and their values at once, using, e.g., my $form = $query->Vars() (which makes $form a reference to an anonymous hash, of which the keys are the form parameter names), then the values will all come out as scalars. In this case, multi-valued parameters have their values represented as a packed string, with the individual values separated by "\0" (the ascii NUL character). So in that case:

my $form = $cgi->Vars(); foreach my $param (keys %$form) { my @values = split /\0/, $form->{$param}; print "$param values are: ", join(', ', @values), "\n"; }

The CGI perldocs are long, comprehensive, and useful. I highly recommend giving them a thorough read.

HTH,
--roundboy


In reply to Re: Re: Reading multiple values from a selection with CGI.pm by roundboy
in thread Reading multiple values from a selection with CGI.pm 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.