How can I get rid of the "Cannot find the method of the object to warn through the error" sssself "package in IE :: Mechanize?

I play with Win32 :: IE :: Mechanize. I am trying to use a script to automatically access my six online accounts. the script basically works, but perl throws out a kind of critical "Cannot find object method" warn "through package" sssself "(maybe you forgot to load" sssself "). Despite the error, the script may still but I want to get rid of it and understand why this is happening. Next is the script. Please kindly let me know where I can improve the code. Thanks, as always.

use strict;
use Win32::IE::Mechanize;


my @accounts = (
'http://mail.21cn.com',
'frmmail1',
    {
        'Username' => 'myusername',
        'passwd' => 'mypassword',
        },
'http://mail.126.com',
'form',
    {
        'user' => 'myusername',
        'password' => 'mypassword',
        },
......
......
......
    );

sub arg{
shift (@accounts);
}

while(@accounts){
my $mech = Win32::IE::Mechanize->new(visible=>1);
my $url = arg;
my $form = arg;
my $account = arg;

$mech->get($url);
$mech->form_name($form);
eval {$mech->set_fields(%$account);}; 
warn $@ if $@;
$mech->click();
}

I know something is wrong with the line

$mech->set_fields(%$account);

But how can I fix this? or i just delete

warn $@ if $@;

, ?

:)

UPDATE

, @daotoad, :) , .

, @Eric, , :)

, , Win32:: IE: Mechanize 0.009 cryptic

"warn" "sssself" (, l lad "sssself"?) C:/Perl/site/lib/Win32/IE/Mechanize.pm 971.

0.009_17 Dev Release :

'Username' E:\mailme.pl 33

, , "UserName", "Username".

, :) , !

+3
2

, Win32:: IE:: Mechanize 0.009 . 0.009_17, . , "sssself" . IE , WWW::Mechanize::Firefox WWW::Mechanize, .

+4

, , . . - , , , .

#!/usr/bin/perl
use strict;
use warnings;  # Use warnings - see perldoc perllexwarn

use Try::Tiny;  # Don't try to handle your own exceptions.  Try::Tiny does it better.

use Win32::IE::Mechanize;

# Use a nested structure so you don't have to keep popping stuff off a global array.   
my @accounts = (

    {   url       => 'http://mail.21cn.com',
        form_id => 'frmmail1',
        fields => {
            Username   => 'myusername',
            passwd     => 'mypassword',
        }
    },
    {   url => 'http://mail.126.com',
        form_id => 'form',
        fields => {
            user => 'myusername',
            password => 'mypassword',
        },
    },
);

# No messing about with @accounts means we can use a for loop.
for my $account (@accounts) {

    # Its not necessary to unpack these into scalars.
    # It makes sense if you are going to transform the values or use them many times.
    my $url    = $account->{url};
    my $form   = $account->{form_id};
    my $fields = $account->{fields};

    my $mech = Win32::IE::Mechanize->new(visible=>1);

    $mech->get($url);
    $mech->form_name($form);

    # Exception handling redone with Try::Tiny    
    $mech->click() if try { 
        $mech->set_fields(%$fields);
        1;
    }
    catch {
        warn "Form failed - $_\n";
    };
}
+2

Source: https://habr.com/ru/post/1734641/


All Articles