Zachary Zachary - 1 year ago 139
Perl Question

Can't call method "header" on an undefined value at WWW/ line 2566

I am just doing a testing using

module on Facebook, when I try to run the code below, it return me an error

Can't call method "header" on an undefined value at C:/Strawberry/perl/vendor/lib/WWW/ line 2566.

#!/usr/bin/perl -w
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
# Connect to server
$mech->get( "" );
$mech->success or die $mech->response->status_line;

# Log into server

$mech->field('email', '');
$mech->field('pass', 'xxxxxxx');
$mech->click_button(value => 'Log In');

Answer Source

Your page is opening in some other language other than English. That's why you are getting that error. If you will open the page in English forcefully then the error will disappear. Try below address:

$mech->get( "" );

or, you may click directly on instance of HTML::Form::SubmitInput obtained using this:

$mech->current_form()->find_input( undef, 'submit');

or, as there is only one click button in the form you can use click with no arguments.


or as suggested by @Borodin you can directly use(as the email and password field aren't translated):

$mech->submit_form( with_fields => { 
                        email => '', 
                        pass => 'xxxxxxx' 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download