0

Here's section of code and i am trying to POST whole array using LWP but server is receiving only first row of array(0 index) while others are not getting sent to server, please guide what i am doing wrong

$data_post[0] = "text1";
$data_post[1] = "text2";
$data_post[2] = "texxt3";
$data_post[3] = "text4";
$data_post[4] ="text5";
my $ua= LWP::UserAgent->new();
my $response = $ua->post( $url, { 'istring' => @data_post} );

my $content  = $response->decoded_content();
my $cgi = CGI->new();
print $cgi->header(), $content;
neo
  • 89
  • 4
  • 11

1 Answers1

6

You can't assign an array to a hash key, only a scalar. Your attempt will expand the array and send this:

{ "istring" => "text1", "text2" => "texxt3", "text4" => "text5" }

Use an array ref instead by putting the "take a reference" operator in front of the array:

{ istring => \@data_post }
brian d foy
  • 129,424
  • 31
  • 207
  • 592
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • @briandfoy - Brian, I am not surprised that you again vote against me (stackoverflow) on the other answer, which OP accepted. If you would take a closer look to my answer, you would see that my first version (before edit/update) has the code `{ istring => \@data_post }` as well, but OP claims that it is not working for him, so then I found a solution that was what OP needed. So I believe my answer should (and is) accepted answer. Hate me - go ahead and run downvotes on all my posts you find... – Ωmega Apr 12 '12 at 12:53
  • 3
    I don't think the OP was running the right code. Since you don't explain your answer using words, it's hard for a newbie to pick out the change of a single \. If you were as verbose in your answers are you are in your trolling comments, you wouldn't have as many problems as you do. – brian d foy Apr 13 '12 at 02:41