in reply to using WWW::Mechanize with loops

If the form permits upload of a file then why not start with the uncomplicated method of submitting one file at a time. Once you've got the hang of that, then it should be a relatively trivial matter to convert this into looping with more than one file at a time.

One method of dealing with 6 files at a time is something like the following:

while ( @files ) { my $num_to_submit = ( @files > 6 ? 6 : @files ); my $f1 = shift @files; my $f2 = shift @files; my $f3 = shift @files; my $f4 = shift @files; my $f5 = shift @files; my $f6 = shift @files; ... $mech->submit_form( ... fname1 => $f1 || '', fname2 => $f2 || '', ... fname6 => $f6 || '', ); }

Replies are listed 'Best First'.
Re^2: using WWW::Mechanize with loops
by Anonymous Monk on Mar 14, 2006 at 04:09 UTC
    Hi.

    One file at a time would be a drag because after each submissions I need to click an email verification link. So I'd have to do some 400 email clicks instead of 1/6 of that submitting full forms.

    Can you explain what my $num_to_submit = ( @files > 6 ? 6 : @files ); Is doing?

      In this context @files returns the number of elements in the array @files. This ternary operator expression (@files > 6 ? 6 : @files) works like this:

      my $number_to_submit=@files; if @files > 6 then $number_to_submit = 6; else $number_to_submit = @files;

      So this limits the number of files to submit to 6 if there are more than 6 files in the array @files.