No need to invoke all that very heavy and possibly not
installed Net::Telnet stuff. Just open the socket!
#!/usr/bin/perl
use strict;
use IO::Socket::INET;
my $c = IO::Socket::INET->new("bofh.jive.org:666") or die "connect: $@
+";
while (<$c>) {
next unless /Your excuse is: (.*)/;
print ucfirst $1, "\n";
exit;
}
Use Net::Telnet when there'll be terminal-like interaction with
prompts and telnet protocol things. If it's just a socket, use the socket code!
-- Randal L. Schwartz, Perl hacker | [reply] [d/l] |
NOTE:
Just for funsies, I slipped this snippet into my former company's error handler CGI. (a simple CGI that caught ErrorDocument redirects from Apache, then printed an appropriate HTML message based on the code).
On top of the 'real' message, I put in the output of this snippet. I ran it 30 or 40 times, funny, not too risque for my boss. No problemo.
2 months later, I am called by the secretary asking why our web site is saying that she has sex with the boss's 8 year old son. There, in living HTML was a BOFH message on her screen.
JUST IN CASE you were thinking about putting this in a 'real' place. Don't :)
-oakbox | [reply] |