【发布时间】:2011-06-15 13:17:12
【问题描述】:
我正在学习一个名为 Programming IRC Bots In Perl 的教程,为我在 Abjects 服务器上的频道制作一个简单的 IRC 机器人,问题是我遇到了一些奇怪的错误。看看:
Nathan-Camposs-MacBook-Pro:Desktop Nathan$ ./bot.pl
./bot.pl:第 1 行:使用:找不到命令
./bot.pl:第 4 行:我的:找不到命令
./bot.pl:第 8 行:意外标记附近的语法错误('my $conn = $irc->newconn('
./bot.pl: line 8:
Nathan-Camposs-MacBook-Pro:桌面 Nathan$
使用此代码:
use Net::IRC;
# create the IRC object
my $irc = new Net::IRC;
# Create a connection object. You can have more than one "connection" per
# IRC object, but we'll just be working with one.
my $conn = $irc->newconn(
Server => shift || 'summer.abjects.net',
# Note: IRC port is normally 6667, but my firewall won't allow it
Port => shift || '6667',
Nick => 'iBot',
Ircname => 'I\'ve bee built by iNathan!',
Username => 'iBot'
);
# We're going to add this to the conn hash so we know what channel we
# want to operate in.
$conn->{channel} = shift || '#MobilePassion';
sub on_connect {
# shift in our connection object that is passed automatically
my $conn = shift;
# when we connect, join our channel and greet it
$conn->join($conn->{channel});
$conn->privmsg($conn->{channel}, 'Hello everyone!');
$conn->{connected} = 1;
}
# The end of MOTD (message of the day), numbered 376 signifies we've connect
$conn->add_handler('376', \&on_connect);
sub on_join {
# get our connection object and the event object, which is passed
# with this event automatically
my ($conn, $event) = @_;
# this is the nick that just joined
my $nick = $event->{nick};
# say hello to the nick in public
$conn->privmsg($conn->{channel}, "Hello, $nick!");
}
$conn->add_handler('join', \&on_join);
$irc->start();
我应该怎么做才能纠正这个问题?
【问题讨论】: