使用 Perl 制作的 IRC 机器人的一些简单错误
我正在遵循一个名为 Programming IRC Bots In Perl 的教程,为 Abjects 服务器上的频道制作一个简单的 IRC 机器人,问题是我遇到了一些奇怪的错误。看一下:
Nathan-Camposs-MacBook-Pro:桌面 Nathan$ ./bot.pl
./bot.pl:第 1 行:使用:找不到命令
./bot.pl:第 4 行:我的:找不到命令
./bot.pl:第 8 行:意外标记附近出现语法错误('
my $conn = $irc->newconn('
./bot.pl: 第 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();
我应该做什么来纠正这个问题?
I'm following a tutorial called Programming IRC Bots In Perl to make a simple IRC bot for my channel at Abjects server, the problem is that I'm getting some weird errors. Take a look:
Nathan-Camposs-MacBook-Pro:Desktop Nathan$ ./bot.pl
./bot.pl: line 1: use: command not found
./bot.pl: line 4: my: command not found
./bot.pl: line 8: syntax error near unexpected token('
my $conn = $irc->newconn('
./bot.pl: line 8:
Nathan-Camposs-MacBook-Pro:Desktop Nathan$
With this code:
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();
What should I do to correct this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在顶部。 /bin/sh 通常不理解 Perl,这就是您所看到的。
另外,我会推荐:
at the top. /bin/sh doesn't generally understand Perl, which is what you're seeing.
Also, I would recommend:
另外,我确信您以前在某处见过和听说过这一点,但帮自己一个忙,不要使用
Net::IRC
...它已经死在水中一段时间了自我宣传7年。新的建议是使用 POE::Component::IRC 或某些变体。虽然
POE::Component::IRC
为您提供了对机器人功能的最大控制、灵活性和可见性,但更简单的方法是Bot::BasicBot
。希望有帮助。
In addition, and I'm sure you've seen and heard this before somewhere, but do yourself a favor and don't use
Net::IRC
... It's been dead in the water for a self advertised 7 years.The new recommendation is to use
POE::Component::IRC
or some variant. WhilePOE::Component::IRC
offers you the most control, flexibility, and visibility into the functions of the bot, a much easier approach isBot::BasicBot
.Hope that helps.
参考 http://freetexthost.com/wdmcihuvxx,您缺少 Net 库。根据您使用的操作系统,您可以通过多种方式获取它 - 或者仅使用 CPAN。
In reference to http://freetexthost.com/wdmcihuvxx, you're missing the Net library. Depending on which OS you're on you have multiple ways of getting it - or just use CPAN.