onperl

Perl programming language

SSHFS on Mac

If you do much work with Perl and web applications then you likely spend a lot of time on Linux. If you're serious about Linux then you probably spend a lot of time typing obscure and arcane command snippets into a terminal window. If you don't love the command line, you soon learn to at least live with it.

RTFM

In a previous post I gave a recipe for creating and verifying CAPTCHA images. In practice that method could be vulnerable to a replay attack. That is, once a valid cookie and image text value were obtained, they could be reused again. This post describes a way to add a timeout, so that the valid value can be made to expire after a short period of time.

Serving XML as JSON

The JSON standard is the good way to deliver data to a JavaScript application, because it is JavaScript. XML is a good way to publish data because it is a popular standard. If only there were some glue to stick these two good things together...

Get Fired

I once swore I would never program in client-side JavaScript again. This was about the time that IE was first starting to take over the world, and Microsoft were promoting rubbish like JScript. Actually I swore a lot back then, but now we have a new age of JavaScript enlightenment, with Ajax, Web 2.0 and FireFox brightening the JavaScript world. Bless you, FireFox.

Of course, I never really stopped writing client-side JavaScript. It's unavoidable. Lately I'm working on a framework to query imported XML objects, in a xpath-like way. Which, it turns out is complicated enough to require some debugging effort. But how much does it suck to have to alert()nine-hundred times? I can tell you it sucks a lot. Haven't things improved any more than that in all these years?

Well, things have improved. A lot. I just discovered a little miracle called FireBug and the only swearing I've done since installing it is of the "Holy $!@ this is good!" variety. More evidence that the future of client-side JavaScript is looking very bright indeed.

Tidy XML

I can never get the tidy tool work as well as the (admittedly heavier) XML::Tidy perl module. Here's a little script I keep around as a better way to tidy up XML.

#!/usr/bin/perl
use strict;
use XML::Tidy;
my $src = shift @ARGV
or die "USAGE: $0 <xmlin> (-|<xmlout>)";
my $out = shift @ARGV;
my $tidy = XML::Tidy->new('filename' => $src);
$tidy->tidy("\t");
$out or print $tidy->toString();
if ($out eq '-') {  $tidy->write() } # overwrite
else { $tidy->write($out) }

Secure Scraping

There are a few CPAN modules I consider "must-haves" and as of today WWW::Mechanize is on that list. If you've ever had to do any screen scraping, parsing HTML on web pages for information, you'll want to try this module too.

Sucking Even Less

A while ago I wrote about TextMate and how it compared to BBEdit. I need to update that comparison now, because BareBones has just released a better BBEdit: version 8.5. Okay, it's still BBEdit, they haven't gone and done anything radical. What have done however is yet another incremental improvement, further proof that BareBones is listening to their users.

Among the least sucking new features is code-folding (at last!), a code clippings menu, better svn support and yes -- finally -- an application icon that doesn't look like it came from 1999. I'd like to see a much cleaner interface overall, and maybe version 9.0 will include such a makeover, but for the time being a rock solid application just got a little bit more solid.

Of Perl and Platypuses

Apple's OS X is an amalgamation of several technologies, including the Unix-based Darwin OS. So it isn't surprising that a platypus named Hexley was chosen as the mascot. I recently happened across another platypus on my Mac, this time with a heart of perl.

Sveinbjorn Thordarson has created an open source tool called Platypus which allows scripting languages, such as Perl, to run as native desktop applications. It's very slick, and works like a treat. If you've ever wanted to use perl in desktop applications on a Mac, you should be running to give this tool a try.

Find Match In A Set

Say you've been given a list of keywords, and you want to find every news item in the database that matches at least one of those keywords. This problem might occur if someone has selected (or typed in) a series of words and wants to do an "OR" search, that is: find all items that match word-one, or word-two, or word-three, etc.