http://www.perlmonks.org?node_id=689492

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

I have logged into my adsl modem using the following code.

use strict; use WWW::Mechanize; use LWP::Simple; use MIME::Base64; my $pubIP = get("http://whatismyip.org/"); my $url = "http://$pubIP/resetrouter.html"; my $username = "foo"; my $password = "bar"; my $button = "Save/Reboot"; my @args = ( Authorization => "Basic " . MIME::Base64::encode( $username . ':' . $password ) ); my $mech = WWW::Mechanize->new(autocheck => 1); $mech->credentials( $url, "test", $username, $password ); $mech->get( $url, @args ) or die $mech->die; print $mech->content; $mech->click($button);

the return value of print $mech->content; is as follows which means i have successfully logged into my adsl modem:

<html> <head> <meta HTTP-EQUIV='Pragma' CONTENT='no-cache'> <link rel="stylesheet" href='stylemain.css' type='text/css'> <link rel="stylesheet" href='colors.css' type='text/css'> <script language="javascript"> <!-- hide function btnReset() { var code = 'location="rebootinfo.cgi"'; eval(code); } function frmLoad() { var sysReboot = '0'; var lanRefresh = '0'; if ( sysReboot == '1' ) btnReset(); else if ( lanRefresh == '1' ) { var code = 'location="resetrouter.cgi?lanRefresh=0"'; eval(code); } } // done hiding --> </script> </head> <body onLoad='frmLoad()'> <blockquote> <center> <br> <strong>Click the button below to save and reboot the rout +er.</strong> </blockquote></center> <p align="center"> <input type='button' onClick='btnReset()' value='Save/Reboot' +> <br> </p> </body> </html>

but immediately after print statement, as i pass through the $mech->click($button) statement i am getting the error Can't call method "click" on an undefined value at c:/Perl/site/lib/WWW/Mechanize.pm line 707.

did lot of googling and searching perl monk as well...got the results as saying the object is not initiated...in my case $mech....but i can't see how.

Please suggest me where am i doing it wrong.