[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-WebCGI] sending an array through CGI



(You have your terminology muddled.  A '%' signifies a hash (aka "an
associative array").  A '@' signifies a list (aka "an array").  But they
are both variations on "arrays". Referring to a hash as "an array" will
only confuse people :^)

At 11:06 -0400 5/27/99, Adam Witney wrote:
> is it possible to send an array through an INPUT tag?

You have done so. A list _is_ an array.

> i can send this ok...
>
> <INPUT TYPE=HIDDEN NAME="name" VALUE="@list">
>
> and then use
>
> @list = $cgi->param('name');

Actually, you could assign to @list even if you didn't have a list in the
VALUE attribute. This is simply a function returning in list context.

> however i cannot send
>
> <INPUT TYPE=HIDDEN NAME="name" VALUE="%array">
>
> this gives the param "name" a value of "%array" instead of the contents of
> %array.... is this possible or am i doing it wrong?

As near as I can tell, there is no way to assign to a hash.  %array is a
hash.
This makes a certain amount of sense, given that param() is a function.
Functions return their values in either list (aka array) or scalar context.
As far as I know "hash context" has not been invented yet.

Also, HTML expects lists of items in the Value attribute... I can't think
what HTML would _do_ with a hash.

As a possible workaround, you could, however, flatten your hash to a list
    [key1, value1, key2, value2, ...]
and send that through, then turn it back into a hash on the other side.

-- --
       |\      _,,,---,,_       Vicki Brown <vlb@cfcl.com>
 ZZZzz /,`.-'`'    -.  ;-;;,_   Journeyman Sourceror: Scripts & Philtres
      |,4-  ) )-,_. ,\ (  `'-'  P.O. Box 1269  San Bruno  CA  94066
     '---''(_/--'  `-'\_) http://www.cfcl.com/~vlb  http://www.macperl.org

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org