我对perl比较陌生,我试图创建一个perl脚本来远程登录web表单并返回成功或失败。但它不工作或者我失去了一些东西,再加上它给我的错误信息:这是我写的:perl中的远程web表单发布
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Response;
use HTTP::Request::Common qw(POST);
$ua = LWP::UserAgent->new;
$ua->agent("Mozilla 8.0...");
$username = "username";
$password = "password";
my $req = (POST 'http://www.domain.com/login.php',
["Username" => "$username",
"Password" => "$password"]);
$request = $ua->request($req);
$content = $request->content;
if ($res->is_success) {
print ("success");
exit;
}
else {
print ("failure");
}
这个脚本不运行在所有和我得到的错误是:
Can't call method "is_success" on an undefined value at c:\remotelogin.pl line 24.
那么,你没有任何名为'$ res'的变量,所以它是有道理的,它是未定义的。 –
使用严格;使用警告; – Bruce
贬低,因为我怀疑这个问题会对其他人有用。如果这个问题纯粹是针对这个特定错误信息的讨论(“不能在未定义的值上调用方法X”)和'use strict;使用警告;',它可能更有用。 –