Hello

There are several problems in your code. I'll list them below. But first, why are you not using Net::IRC? If you want to reinvent the wheel, then why are you not using IO::Socket::INET? Why are you doing all the dirty work yourself?

Here are the things that are causing the problems:

  1. $botnick is used but never defined.
  2. $name also is used but never defined.
  3. You are using sysread to read from the socket, however, IRC is not a binary protocol. You should use <SOCK> instead.
  4. You are reading one char at a time which is not what you should do.
  5. This segment will always return an empty string:
     if ($inchar eq "\n") # $inchar is one char long
            {
              chop $inline; # remove it
              return $inline; # return empty.
            }
  6. You are defining the function connec which does the connect but never actually calling it.
  7. It works after fixing all the above points.

Now back to using IO::Socket::INET, the above code can be shortened to:

use IO::Socket; my $server = 'irc.openprojects.net'; my $port = 6667; my $nick = 'aziz'; my $name = 'Abdulaziz Ghuloum'; my $sock = IO::Socket::INET->new( PeerAddr => $server, PeerPort => $port) or die "Cannot connect: $!\n"; print $sock "USER $nick buf buf :$name\r\n"; print $sock "NICK $nick\r\n"; while(<$sock>){ print; my ($pingchk,$rest)=split(/ /,$_,2); if ($pingchk eq 'PING') { print $sock "PONG $rest\r\n"; } }
Hope this helps,,,

Aziz,,,


In reply to Re: perl bot problems by abstracts
in thread perl bot problems by Anonymous Monk

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.