in reply to Re: WWW:Mechanize problems
in thread WWW:Mechanize problems

Thanks! I'm getting closer. I'm not sure about the submit==1 yet. I moved form loop print statement into the form loop. Now the form count is incrementing. And my intent is to set submit="0" only if it is false for any passthrough. How can I do that? Thanks!

Replies are listed 'Best First'.
Re^3: WWW:Mechanize problems
by GrandFather (Saint) on Mar 29, 2007 at 01:47 UTC

    What condition do you want to set it true for?

    It looks to me like your tests would be better structured:

    if($inputfield =~ m/(F|f)(irst)?name/) { $mech->set_fields( $inputfield => $fname); print "matched firstname regex\n"; } elsif ($inputfield =~ /(L|l)(ast)?name/) { $mech->set_fields( $inputfield => $lname); } elsif ($inputfield =~ /(A|a)ddress[123]?/) { $mech->set_fields( $inputfield => $address); } elsif ... } else { $submit="0"; print "Setting submit=0\n"; }

    DWIM is Perl's answer to Gödel
      I would like to set it true if it does not match any of the regular expressions listed. I have restructured it like this:
      foreach my $inputfield (@inputfields) { if($inputfield =~ /(F|f)(irst)?name/) { $mech->set_fields( $inputfield => $fname); print "matched firstname regex\n"; } elsif($inputfield =~ /(L|l)(ast)?name/) { $mech->set_fields( $inputfield => $lname); } elsif($inputfield =~ /(A|a)ddress[123]?/) { $mech->set_fields( $inputfield => $address); } elsif($inputfield =~ /(C|c)ity/) { $mech->set_fields( $inputfield => $city); } elsif($inputfield =~ /(S|s)tate/) { $mech->set_fields( $inputfield => $state); } elsif($inputfield =~ /(Z|z)ip/) { $mech->set_fields( $inputfield => $zip); } elsif($inputfield =~ /(P|p)hone/) { $mech->set_fields( $inputfield => $phone); } else { $submit="0"; print "Setting submit=0\n"; } }
      And it doesn't look like any of my regex's are matching. But if I take the else line out, it submits the form no problem. Any thoughts?

        As a diagnostic you could print what it's failing to match in the else.


        DWIM is Perl's answer to Gödel