woozy has asked for the wisdom of the Perl Monks concerning the following question:
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
but that just seems so ... inelegent.foreach $ ($query->param){ @a = $query->param($key); if (@a > 1){ $a = $query->param($key) } }
===
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.
|
|---|