It was some 3 or 4 years ago I wrote this bit, basically it'll execute find on your *nix system, find all perl/C source code (.pl/.c) and print it out character by character with a half second delay. I was going to turn it into a screen saver for KDE, i guess i got sidetracked. Im just posting this to get the Perl section moving a little bit, i'll browse my old tarballs of perl code and see if i cant..
Also, watch those 'bad habits' yourself...
You forgot
#!/usr/bin/perl
use warnings;
use strict;
Don't wanna get into bad habits now ;)
use IO::Socket;
use warnings;
use strict;
$sock = IO::Socket::INET->new(
PeerAddr => 'server_here',
PeerPort => 6667,
Proto => 'tcp' ) or die "could not make the connection";
You forgot to actuall `use' strict.
Not to mention... youre re-inventing the wheel. look into PoCo::IRC
sorry to bust your bubble kid, but the first loop is all that will be engaged since its infinite. also, why not the newlines off...
#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket::INET;
my ($host,$port,$nick,$ident,$real,$chan) = @ARGV;
die("usage: $0 <irc.server.net> <6667> <nick> <ident> <realname> <#channel>") unless $chan;
my $socket = IO::Socket::INET->new( PeerAddr => $chan,
PeerPort => $port,
Proto => 'tcp',
Timeout => 2,
) or die("Cant create socket: $!");
sub smsg { print $socket "PRIVMSG $_[0] :$_[1]\r\n"; }
sub sraw { print $socket "$_[0]\r\n"; }
sraw("NICK $nick");
sraw("USER $ident 8 * :$real");
sraw("JOIN $chan");
while(chomp(my $body = <$socket>)){
if($body =~ /PING(.+)/){ sraw("PONG $1"); }
if($body =~ /$chan :ohai $nick/i){ smsg($chan,"ohai back!"); }
}