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

Hi everyone, I am trying to write my first CGI script and am using WWW::Mechanize. I have a multi-line text box on a form and collect the data using
my $form_comments = $query->param('comments');
This will store all the lines of text into a string, correct? I then have $form_comments passed using submit to another script where it scrapes another website and enters $form_comments by using:
$agent->field("COMMENT", join("\n", "$ARGV[4]"));
When I do this, only the first line of my $form_comments is actually filled into the box. Does anyone know why this may be happening? ($form_comments when being passed using submit turns into $ARGV4]) Thanks in advance!

Replies are listed 'Best First'.
Re: WWW::Mechanize help
by moritz (Cardinal) on Aug 19, 2008 at 20:53 UTC
    $agent->field("COMMENT", join("\n", "$ARGV[4]"));

    You're not even using the variable $form_comments in this line, and I don't see any connection to $ARGV[4] at all. (Why do you access @ARGV in a CGI script anyway? CGI.pm should take care of this.)

    So either you have a simple thinko, or you're not showing the relevant part of the script.

    Update: this: join("\n", "$ARGV[4]") is just the same as $ARGV[4], because "$ARGV[4]" is a scalar, thus join will do nothing to it.

      I thought I explained that. $form_comments is passed to another Perl script along with other parameters. When you use: system ("submit.pl", ...$form_comments does it not push that variable into ARGV? ?
        There is no such limitation, if you do it right:
        $ cat foo.pl #!/usr/bin/perl use strict; use warnings; use Data::Dumper; if (@ARGV){ print Dumper \@ARGV; } else { system $^X, $0, "a\nb"; } __END__ $ perl foo.pl $VAR1 = [ 'a b' ];

        You can see that the script calls a copy of itself, and both lines of a\nb are passed correctly to the second copy (tested on Linux).

        Which makes me think that you're doing something wrong.

      On your update, I took out the join statement and set it as  $agent->field("COMMENT", $ARGV[4]); . If what I fille in on my form is EzBR Warnings:
      - Klocwork Complexity:NOT OK (empty)
      - Klocwork Inforce:NOT OK (empty)
      - UnitTest enclosure:OK
      The only line from the text box that gets passed is "EzBR Warnings:" and none of the following lines. Any idea on how to make it all be passed? To summarize, there is a website we use at work that takes way too much time to fill out, so I made another site than has a form with fewer inputs, takes that input and then scrapes the original site with WWW::Mechanzie
        Again if you do it properly, it should work. Which means that you are not doing it properly. Which in turn means that your error is somewhere around line 42.

        Or in other words: If you don't show us the code, we can't tell.

        Show us a very simple, reduce example that demonstrates your problem. It doesn't have to use WWW::Mechanize at it, it can just pass around constant string.