RainDog has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to get the syntax right to post a multivalue variable using HTTP::Request::Common. I'm currently posting variables just fine using a hash:
%form_vals=(var1=>val1,var2=>val2) etc.
But now I need to post a series of values that all have the same form variable name. The perldoc only has one line about it with no example, and I'm not quite smart enough to get over the hurdle.

I tried creating the values in a list:
push(@val_list,$val)
and then putting multival=>\@val_list in my hash, but I don't think that's right. And I don't think I can put multiple instances of the same var name into the hash, can I? That just doesn't make sense to me:
%form_vals=(multival=>val1, multival =>val2, multival =>val3);
??

Replies are listed 'Best First'.
Re: multivalue variable in http::request
by NetWallah (Canon) on Jan 09, 2008 at 05:53 UTC
    From the docs,

      this function also takes a second optional array or hash reference parameter.

    Not having played it myself, I can only conjecture that this should work:

    my @form_vals=(multival=>'val1', multival =>'val2', multival =>'val3 +'); # or , alternatively, my @form_vals=(single=>'Single Value', multival=>[ 'a', 'list', ' +of', 'values']); # Pass a ref to @form_vals , when you POST.

         "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom