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:
- $botnick is used but never defined.
- $name also is used but never defined.
- You are using sysread to read from the socket, however, IRC is not a binary protocol. You should use <SOCK> instead.
- You are reading one char at a time which is not what you should do.
- 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.
}
- You are defining the function connec which does the connect but never actually calling it.
- 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,,,
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.