Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Clear questions and runnable code
get the best and fastest answer

RFC: Tutorial - IRC Programming In Perl

by mmmmtmmmm (Monk)
on Aug 29, 2007 at 23:32 UTC ( #635955=perlmeditation: print w/ replies, xml ) Need Help??

Hello Everyone,

I have been working on a resource list for basic IRC programming in Perl. I noticed that there was no comprehensive tutorial node on perlmonks that discusses IRC programming, which is something I happened to have been reading about a lot lately. So I have written up a draft for the tutorials section or Q&A. I could use any advice you can offer involving content that needs to be added or sections that need to be modified. I definitely want to add more detail to the modules and server sections, and I was debating whether or not I should add some of my own code, as there is already plenty of fine example code elsewhere (which is linked from my node anyway). But if you see a reason for doing it over, I could maybe throw together a simple bot or something to illustrate some basic concepts.

It's not meant to be a full tutorial - there have been plenty written already. I just wanted to give people enough to enable them to learn more on their own. Here's what I've got so far. What would you change about it?

IRC Programming In Perl

Recently, I have started teaching myself how to write Perl programs for IRC (Internet Relay Chat). Here is a listing of a few resources that I have found helpful for learning to write my own IRC clients and servers in Perl.

Basic IRC Usage

If you haven't used IRC yet, it would probably be a good idea to play around with someone elses client, before you bother trying to write your own. IRC is a great tool for anyone learning to program Perl -- it is a great way to get real-time assistance, share your knowledge with other people, and just talk about interesting topics related to Perl. Check out the #Perl and #PerlHelp channels at, as well as the #Perl channel at

Please be sure to read the guidelines for the channels before you post to them...

For those of you who have not used IRC before, or who need a quick refresher, here is a listing of IRC Commands
IRC Commands.

Be sure you use it safely:
IRC Security

And here's a more detailed reference:
IRC Help Directory

IRC Clients that run Perl Scripts:

A great way to practice your Perl programming skills is to get a lightweight IRC client that is configured and operated via Perl scripts -- two such clients are sirc && irssi. And using a simple client is generally a more secure method of connecting to IRC than using a bloated (read: buggy & insecure) graphical client.

The irssi website has a large collection of scripts that you can look through to learn a bit about how they are written. You can find that collection below, as well as a link to a guide to writing Perl scripts for irsii:

Irssi Script Collection
irssi - Perl Scripting Reference
Irssi - Juerd's Site

There are many other clients to choose from as well -- a quick Google search for "irc client" will give you an idea of what's available to you.

Perl Modules For IRC

There are several modules on CPAN related to IRC. Here are some of those most commonly used:


As I mentioned earlier, although it might be useful to learn how to use Net::IRC (for things like modifying legacy code that uses it, etc), for the most part you will want to use POE::Component::IRC. It will make your life much easier.

Writing IRC Bots

Programming your own IRC bots is fun and is a great method for practicing all manner of programming skills -- especially linguistics and pattern matching. Analyzing the text from so many different people speaking, is quite a challenge. Plus it can be quite entertaining. But just be sure that your bot doesn't become a nuisance and interfere with other people's discussions or eat up the server's resources with needless chatter. Be respectful!

The following is a great beginner's resource for programming your own simple IRC bots using the Net::IRC module:

Programming IRC Bots In Perl

Note: You will probably want to start using the POE::Component::IRC module instead. However by learning the Net::IRC module, you might gain a deeper understanding of the POE::Component::IRC method, as you will have to build the event handling functionality in yourself.

The POE Cookbook has an excellent set of resources on programming IRC bots using the Perl Object Environment modules. They POE::Component modules' documentation is also excellent, so if you want to know about it, that will be the great place to start (here's that link again POE::Component::IRC)

There are also several CPAN bot modules. Check out these modules if you want to see some working bot code:


Running an IRC Server

It is quite easy to use Perl to write your own IRC server programs as well. For this, you will likely want to use the POE::Component::Server::IRC module. Like its client counterpart, the documentation is excellent:


To allow users to engage in meaningful conversation, you have to filter out a lot of garbage that floats in from the internet. This will help you with that:

IRC Operator's Guide

And of course, the usual rules still apply -- always be very cautious when allowing strangers to connect to services running on your server. If you are planning to start your own server, and you haven't read the security guide above, perhaps now is a good time to do so...

The IRC Protocol

And if you really want to get down. Here are some resources on the technical details behind the IRC protocols:

RFC 1459: Internet Relay Chat Protocol
RFC 2810: Internet Relay Chat: Architecture
RFC 2811: Internet Relay Chat: Channel Management
RFC 2812: Internet Relay Chat: Client Protocol
RFC 2813: Internet Relay Chat: Server Protocol

There is much more out there, but hopefully, once you have looked over the stuff above, you will know where to go from here.


Comment on RFC: Tutorial - IRC Programming In Perl
Re: RFC: Tutorial - IRC Programming In Perl
by moritz (Cardinal) on Aug 30, 2007 at 06:34 UTC
    I like your Tutorial/RFC. I wrote two bots lately, and some of my work would have been easier if I had such a comprehensive collection of links.

    I haven't read all your links, but something seems to miss: there is now description of how to handle different charsets in IRC. This is something that can be a pain to handle, and the documentation mostly ignores the issue .

    Net:IRC and POE::Component::IRC don't mention it, Bot::BasicBot offers to set one possible encoding, which is not always sufficient.

    Also I did try to write a logging script with irssi, but I couldn't find a reference manual for If there is such a documentation it would be worthy to point to it directly, maybe I'm not the only one who is too dumb to find it.

      moritz --

      I have done a bit of searching, but could not find either of the things you requested. I will keep looking for more information on using different character sets and, and will post anything I find that is good quality.

      Anyhow, I did find a new link to a "Perl Scripting Reference" for irsii, and added it to the Tut.

      Thanks for the input,
        mmmmtmmmm: POE::Component::IRC's Logger plugin handles encodings the way recent mIRC (and irssi/xchat if configured right) versions do. I suggest you take a look at the source code.
Re: RFC: Tutorial - IRC Programming In Perl
by mmmmtmmmm (Monk) on Sep 01, 2007 at 11:37 UTC
    Update: Found another good irssi scripting site and added it to the list.

    moritz -- I'm still searching for the things you requested. Sorry, but no luck yet...

    Anyone else have anything they would like to add or change?

Re: RFC: Tutorial - IRC Programming In Perl
by rowdog (Curate) on Jun 08, 2008 at 05:40 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://635955]
Approved by bobf
Front-paged by gmax
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2014-04-19 05:02 GMT
Find Nodes?
    Voting Booth?

    April first is:

    Results (478 votes), past polls