Drgan has asked for the wisdom of the Perl Monks concerning the following question:
I have recently decided to pick up on an older project of mine since I now have to do some more fun stuff with Perl. In the midst of looking over the code, I've found a spot where I'm not sure I should be calling RegEx immediately. Possibly, I should send the string to a sub-routine (callback) and then run the RegEx through the sub-routine? Please provide any incite that you may have.
Thanks,Side note: I know I may be better serviced using Net::IRC but I have chosen to dabble with IO:Socket instead.
my $sock = IO::Socket::INET->new( Proto=>"$config->{protocol}", PeerAddr=>"$config->{server}", PeerPort=>"$config->{port}", ) or die "Cannot Connect to Server"; $sock->send("NICK $config->{nick}\n"); $sock->send("USER " . $config->{ident} x 3 . ":$config->{ircname}\n"); $sock->autoflush(1); my %userAuthenticatedList; # Authenticated Users and Host +s my %channels; # Stored List of channels kick +ed from my $connected; # Prevent constant "log-on" of + Bot my $salt = $config->{salt}; # md5 key for encryption my $incomingMessage; # Handle incoming signals/events from +server. while (1) { $sock->recv($incomingMessage, 1024); if ($incomingMessage=~/PING :(.*)/i) { $sock->send("PONG :$1\n"); &on_connect_join() if (!$connected); # The portion determines if the channel is # is a valid entry in the channels channels # hash/array before joining the channel. foreach (keys %channels) { &join_chan($_) if ($channels{$_}); } } # Syntax from server is as follows # :NickName!User@host PRIVMSG (individual/#channel) :text if ($incomingMessage=~/:(.*)!(.*)@(.*) PRIVMSG (.*) :$config-> +{CMDCHAR}(.*)/i) { my $userName = "$1"; my $userHost = $1 . "!" . $2 . "@" . $3; $_ = "$5"; my @args = split " ", $_; my $commands = shift(@args); my $args = "@args"; print "Someting was received\n"; print "$userName $userHost : $commands $args\n"; if ($commands eq "identify") { # Check for co +mmand being called. $args = md5_base64($args, $salt); print "Sent to userLogin\n" if userLogin($user +Name, $userHost, $args); } elsif ($userHost eq $userAuthenticatedList{$userName +}) { for (my $i=0; $pFuncsA[$i]->{command}; $i++) { if ($pFuncsA[$i]->{command} eq $comman +ds) { $pFuncsA[$i]->{func}($args); } } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Looking for a faster method
by rodion (Chaplain) on Dec 28, 2006 at 16:13 UTC | |
Re: Looking for a faster method
by alpha (Scribe) on Dec 28, 2006 at 15:25 UTC | |
Re: Looking for a faster method
by ysth (Canon) on Dec 29, 2006 at 03:16 UTC | |
by Drgan (Beadle) on Dec 29, 2006 at 19:27 UTC |