4

I am creating a script that logs into a web form in Perl using the mechanize module, and I'm getting the error:

syntax error at /home/arty/scripts/gmail_pw_chngr.pl line 18, near "button" Execution of /home/arty/scripts/gmail_pw_chngr.pl aborted due to compilation errors.

Code

    use WWW::Mechanize;
    my $mech = WWW::Mechanize->new();

    my $url = "https://accounts.google.com/Login";

    $mech->get($url);

    $result = $mech->submit_form(
        form_name => 'gaia_loginform', # Name of the form
        #Instead of form name you can specify
        #form_number => 1
        fields       =>
        {
            Email  => 'arty32l@gmail.com', # Name of the input field and value
            Passwd => 'password',
        }
        button    => 'signIn' # Name of the submit button
    );
    print $result->content();

Above is the code, all the values from the input are the name, but it always errors on the same line.

Community
  • 1
  • 1
user1664433
  • 63
  • 3
  • 9

3 Answers3

7

The error in question is the missing comma before button.

ikegami
  • 367,544
  • 15
  • 269
  • 518
3

Use use strict; and use warnings;. They would help you.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
varnie
  • 2,523
  • 3
  • 35
  • 42
  • `use strict` and `use warnings`, while generally excellent recommendations for avoiding hard to detect run-time errors, would be little value here as the OP already has a compile-time error message. – tjd Jun 01 '15 at 16:30
0
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

use WWW::Mechanize;
    my $mech = WWW::Mechanize->new();

    my $url = "https://accounts.google.com/Login";

    $mech->get($url);


    $result = $mech->submit_form(
    form_name => 'gaia_loginform', #name of the form
    #instead of form name you can specify
    #form_number => 1
    fields      =>
    {
     Email    => 'arty32l@gmail.com', # name of the input field and value
     Passwd    => 'password',
    }
    ,button    => 'signIn' #name of the submit button
    );

     print $result->content();
Bill
  • 15
  • 6