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

Hi Monks, I wrote a perl script to send sms to mobile using mechanize module. But when I tried to run it I am getting following error Can't call method "value" on an undefined value at D:/Perl64/lib/WWW/Mechanize.pm line 1403.Here is my code for your reference
#!/usr/bin/perl use WWW::Mechanize; my $mechObj = WWW::Mechanize->new(); if( scalar(@ARGV) ne 4) { help(); } my $username = $ARGV[0]; my $password = $ARGV[1]; my $recvNo = $ARGV[2]; my $textMsg = $ARGV[3]; $mechObj->get("http://wwwl.way2sms.com/content/index.html"); unless( $mechObj->success() ) { exit; } $mechObj->form_number(1); $mechObj->field('username', $username); $mechObj->field('password', $password); $mechObj->submit_form(); $mechObj->get("http://wwwl.way2sms.com//jsp/InstantSMS.jsp?val=0"); $mechObj->form_number(1); $mechObj->field("MobNo",$recvNo); $mechObj->field("textArea",$textMsg); $mechObj->submit_form(); if($mechObj->success()) { print "Done \n"; } else { print "Failed \n"; } sub help { print "\nUsage:\n"; print "\tScriptname.pl <user_name> <password> <receiver_name> <msg +>\n"; exit(0); }
Please help me to rectify this error

Replies are listed 'Best First'.
Re: Perl Mechanize - Can't call method value
by Corion (Patriarch) on Mar 26, 2011 at 18:48 UTC

    Most likely, this call:

    $mechObj->form_number(1);

    fails, as maybe there is no form on the page you get.

      I even replaced with form_name() but still getting same error.

        If there is no (first) form on the page, why do you expect to find one by its name?

        See WWW::Mechanize->dump_forms and ->content to inspect the current page and to find what is there and what is not.

Re: Perl Mechanize - Can't call method value
by ww (Archbishop) on Mar 26, 2011 at 19:41 UTC
    Here's what you're trying to attack: <form name="loginform" action="" method="post">

    Your comment in your child node might mean that you literally tried to use form_name() which I don't believe would work even if you were dealing with pure html, rather than all the [@!_#S* expurgated] js actually found.

    You may want to try Super Search using variants of this.