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

Im learning to use Mechanize, wrote a small program and am getting this error when compiled: Can't locate object method "form" via package "WWW::Mechanize" Here is the code....
use strict; use WWW::Mechanize; use HTML::TokeParser; my $agent = WWW::Mechanize->new(); $agent->get("http://sample.com"); $agent->form(3);
and so on. But form(3) is where the problem is. Any suggestions? Running Perl on Komodo for Windows.

Replies are listed 'Best First'.
Re: WWW:Mechanize Problem
by kyle (Abbot) on May 24, 2008 at 01:07 UTC
      I think that is to specify a form by name, form() is supposed to be used to specify which form on the page. Here is the tutorial i am using http://www.perl.com/pub/a/2003/01/22/mechanize.html

        The tutorial you're using is over five years old. In the meantime, it appears that form() has become form_number(). Looking at the WWW::Mechanize documentation, I see no form() method listed, but form_number() does what you want.

        form() was valid at the time the tutorial was written (2003) — in the meantime it's form_name() (name based) or form_number() (numeric index). The change was made to accommodate for the rare case that a form is named "3" (i.e. name, not index)...