Archive for the ‘Perl’ Category

Banging out an AIM bot

Sunday, June 25th, 2006

I’m not a Perl developer by any means (Python’s my poison) but I wanted to build a quick AIM bot, and Perl’s OSCAR.pm lets you do it in less than 20 lines of code. It’s insane how simple this is:

use warnings;
use strict;
use Net::OSCAR qw(:standard);
my $oscar;
$oscar = Net::OSCAR->new();
$oscar->set_callback_im_in(&im_in);
$oscar->signon($screenname, $password);
while(1)
{
$oscar->do_one_loop();
}
sub im_in {
my($oscar, $sender, $message, $is_away) = @_;
print "[AWAY] ” if $is_away;
print “$sender: $message\n”;
$response = “Hello”;
$oscar->send_im($sender, $response);
}

I wrote a bot which executes a shell script that reads and writes to your todo.txt (more on that in a minute.) Mark ran with the idea and we discussed keeping a bot that can run other scripts on your computer, like “open VNC port” instead of using port knocking or leaving your server port open at all times. The trick is the bot only runs commands from authorized AIM names. I’m not sure how secure that is, but it is a neat idea.

Build Your Own AIM Answerbot [On LAMP]

FileChucker: AJAX File Upload Script with Progress Bar

Friday, February 24th, 2006

FileChucker’s a $15 Perl script that provides an Ajax-y file upload interface for your web site, complete with progress bar. Haven’t tried it, but looks pretty cool.

FileChucker: AJAX File Upload Script with Progress Bar [Encodable Industries]

Quote of the day

Thursday, December 22nd, 2005

“The main class is like a three thousand line Perl file. Run as CGI!!! That’s like, fifty times wacko!”

Perl global search and replace

Tuesday, September 13th, 2005

I produce a monthly web magazine which consists of eight years worth of flat HTML files. One of the writers, who recently got a new email address, asked me to update it everywhere it appeared on the site - which was in dozens of .htm and .html files nested in subdirectories all over the tree. The very thought gave me a headache.

But, after a little researching, I found this quick Perl script did the trick on files piped from the find command:

[trapani@colossus html]$ find . -name “*.htm*” | xargs perl -pi -e ’s/user\@oldaddress.com/user\@newaddress.com/g’

Scary, running that sucker a bit recklessly on the production server, but it totally worked, and fast. Modified from the suggestion at this O’Reilly Linux Server Hack.