我制作了一个Perl脚本。加载后它第一次运行正常,但是当我尝试再次使用它时它不起作用。在irssi我得到:
Irssi: Not enough parameters given error.
我的代码:
use Irssi;
use vars qw($VERSION %IRSSI);
use LWP::UserAgent;
use HTML::LinkExtor;
use URI::URL;
$VERSION = "1.0";
%IRSSI = (
authors => 'PrincessLeia2',
contact => 'lyz\@princessleia.com ',
name => 'gimmie',
description => 'a bot script, using ! followed by anything the script will say (as an action): gets nickname anything',
license => 'GNU GPL v2 or later',
url => 'http://www.princessleia.com/'
);
sub event_privmsg {
my ($server, $data, $nick, $mask, $target) =@_;
my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;
# return if ( $text !~ /^!/i );
if ( $text =~ /!szukaj/ ) {
$text = substr($text, 8);
$url = "http://www.bing.com/search?q=$text&qs=n&form=QBLH&pq=$text&sc=8-4&sp=-1&sk="; # for instance
$ua = LWP::UserAgent->new;
#$server->command ( "action $target $url" );
$server->command ( "action $target @imgs" );
# Set up a callback that collect image links
my @imgs = ();
sub callback {
my($tag, %attr) = @_;
return if $tag eq 'bing'; # we only look closer at <img ...>
push(@imgs, values %attr);
}
# Make the parser. Unfortunately, we don't know the base yet
# (it might be different from $url)
$p = HTML::LinkExtor->new(\&callback);
# Request document and parse it as it arrives
$res = $ua->request(HTTP::Request->new(GET => $url),
sub {$p->parse($_[0])});
# Expand all image URLs to absolute ones
my $base = $res->base;
@imgs = map { $_ = url($_, $base)->abs; } @imgs;
$server->command ( "action $target @imgs[25]" );
@imgs = ();
$p = ();
undef @imgs;
undef $text;
undef $p;
undef $url;
} else {
}
}
Irssi::signal_add('event privmsg', 'event_privmsg');
它出了什么问题?