#! /usr/bin/perl -w use strict; use Getopt::Long; use Net::IRC; sub usage () { print <<"EOF"; Usage: $0 [options] command [arguments] EOF print <<'EOF'; Options are as follows, with defaults in brackets: -n, --nick=[$IRCNICK] IRC nickname. -s, --server=[$IRCSERVER] IRC server. Available commands (with arguments) are: who #channel List the visible users on a channel. whois username ... Query information about particular users. EOF exit 1; } my %options = ( nick => $ENV{IRCNICK}, server => $ENV{IRCSERVER}, ); GetOptions(\%options, 'help|h|?', 'nick|n=s', 'server|s=s', ); usage if $options{help}; my $command = shift or usage; $command = lc $command; if ($command eq 'who') { scalar @ARGV == 1 or usage; } elsif ($command eq 'whois') { scalar @ARGV > 0 or usage; } else { usage; } my $irc = new Net::IRC; my $conn = $irc->newconn(Nick => $mynick, Server => $server) or die "$0: can't connect to IRC server"; sub on_connect { my $self = shift; $self->who($targetchannel); } sub on_whoreply { my ($self, $event) = @_; my ($me, $channel, $user, $host, $server, $nick, $status, $realname) = $event->args; printf "\%-12s \%s\n", $nick, $realname; } sub on_endofwho { my $self = shift; $self->quit; exit; } $conn->add_handler('376', \&on_connect); $conn->add_handler('352', \&on_whoreply); $conn->add_handler('315', \&on_endofwho); $irc->start;