Okay, I'm have a *teensy* problem with CGI.pm

If I make a CGI object: $query I can get the parameter (or cookie) value by calling

$a=$query->param('key'); (or $a=$query->cookie('key');)

if the parameter is an array I can do

@a = $query->param('key');

kinda cool. *BUT* if I want to do something like

foreach $key ($query->param){
... something with $query->param($key) ...
}

$query->param($key) may or may not be an array. How can I know which?

===
well chromatic had the only real solution although it seems pretty inelegent. I guess I didn't make myself clear. When I said how do "I" know, I meant how can my program know, or more accurately how can I program generically. The "foreach" was not to go through the values of a $query->param('key') but to go through all parameters most of which are scalar values but a few of which are lists.

Basically, what I want is something like this:

foreach $key ($query->param){
@a or $a = $query->param($key) depending on whether or not $query->param($key) is a list or a single value
}

I can do

foreach $ ($query->param){ @a = $query->param($key); if (@a > 1){ $a = $query->param($key) } }
but that just seems so ... inelegent.

===

Update to an update: Actually what I really wanted to do was:

$condition{$key} = \@{$query->param($key)} || $condition{$key} = $query->param($key);

but that doesn't work.


In reply to CGI.pm: $q->param can be an array. Can be a single value. How do you know which? by woozy

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.