Update 1: Corrected formating in post.
Update 2: Updated a for-each loop to have documentation explaining what it does. Also changed it to call a sub-routine rather than do the work manually.

Fellow monks,

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); } } } }
"I have said, Ye are gods; and all of you are children of the most High." - Psalms 82:6

In reply to Looking for a faster method by Drgan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.