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

I've got a text file I read into a variable (file3) then attempt to post. The form text area is "form_zone" and consists of many lines. With the same code I'm able to login to the site in a previous step so the problem must be the data from file3 is only outputting the first line of the text file.

A code snippet:

my $response = POST (URI, [ form_zone => @file3, submit => 'Submit', f +orm_result => 'true', menu => 'edit_dns', user => 'username', auth => + '*:strange_string', account => 'account_name', mbox => ''], REFERRER + => LAST_PAGE); $request = $ua->request($response); if ($request->is_success) { print $request->content, "\n"; } else { print $request->status_line, "\n"; }

Any ideas would help!

TIA

20041228 Janitored by Corion: Fixed formatting

Replies are listed 'Best First'.
Re: LWP/HTTP::Request::Common - form submission
by Jenda (Abbot) on Dec 28, 2004 at 21:18 UTC

    You need to read the file into a single scalar, not an array like this:

    my $file3 = do {local $/; <FILEHANDLE>};
    and then use:
    my $response = POST (URI, [ form_zone => $file3, submit => 'Submit', form_result => 'true', menu => 'edit_dns', user => 'username', auth => '*:strange_string', account => 'account_name', mbox => ''], REFERRER => LAST_PAGE);
    Try this to see what did you actually pass to the POST() function:
    my $aref = [ form_zone => @file3, submit => 'Submit', form_result => 'true', menu => 'edit_dns', user => 'username', auth => '*:strange_string', account => 'account_name', mbox => '']; print "( '", join("', '", @$aref), "')\n";
    Do you see what happened? The whole @file3 array was flattened into the array in the square brackets.

    Jenda
    We'd like to help you learn to help yourself
    Look around you, all you see are sympathetic eyes
    Stroll around the grounds until you feel at home
       -- P. Simon in Mrs. Robinson

      Some code may help...

      open (FINALDNS, "final.txt");
      #my @file3 = <FINALDNS>;
      my $file3 = do {local $/; FINALDNS};
      close FINALDNS;

      Jenda,

      I suspect you're right.

      my $file3 = do {local $/; FINALDNS};

      Bareword "FINALDNS" not allowed while "strict subs" in use

      Did I do that right?