Month: February 2008

Leopard cheat sheet

February 14, 2008 Tools No comments

Here’s a handy little cheat sheet for Mac OS X Leopard from O’Reilly. I didn’t realize there were so many Finder shortcuts! Command-T puts something in the sidebar! Command-Shift-G lets you type in a folder name! Cool!

The perils of Perl 5’s indirect object syntax

February 13, 2008 Perl 6 3 comments

Perl lets you call object methods in two different ways:

  • $obj->method()
  • method $obj

The latter form is usually called only for things like clone $obj, which is pretty ugly.
For more about indirect object syntax and some of the pain it causes, see When Is Backwards-Compatibility Not Worth It?.

It’s funny that Max posted that blog entry the other day, because I just was shown a problem that was caused indirectly by it. Mike O’Regan showed me some code that he was surprised even compiled, because it certainly wasn’t working.

sub custom_sort {
return
$a->{foo} cmp $b->{foo}
||
a$->{bar} cmp b$->{bar}
}

See the a$ instead of $a? Yuck. But it compiles just fine. Why? Well, let’s see what B::Deparse decompiles it out as:

$ perl -MO=Deparse foo.pl
sub custom_sort {
return $$a{'foo'} cmp $$b{'foo'} || $-->a > {'bar'} cmp $-->b > {'bar'};
}
foo.pl syntax OK

Turns out that it’s calling method a on the object $- and then seeing if that is greater than {'bar'}. Double-ugh.

Perl 6 still has indirect object syntax, but you must follow it with a colon, as in method $obj: @args. Larry says in Perl 6 it’s completely unambiguous.

Tell us how to do it, Andi!

February 12, 2008 Perl 6 8 comments

Andi Gutmans, founder of Zend which drives PHP, takes a swipe at Perl 6 in this interview:

So we are anticipating a long rollout cycle for PHP 6, and we did not want to take the same route that the Perl project did, with project contributors still working on Perl 6 I think six years later. People make fun of Microsoft, but take a look at Perl 6. . . .

Sure, PHP 6 may have a shorter release cycle than Perl 6 has, but at the end of it all, we’ll have Perl 6, and you’ll still have PHP.

Just sayin’.

xoxo,
Andy

How to: Find all modules used in a tree

February 7, 2008 Regexes, Tools 1 comment

On the perl-qa list tonight, we were discussing how best to find all the modules used in a source tree. To do the job right, you’d have to run the code and then look at the %INC:: hash, which shows the paths of all modules loaded. The low-tech and usually-good-enough solutions we came up with use ack:

$ ack -h '^uses+(w+(?:::w+)*).*' --output=$1 | sort -u

Thanks to Andy Armstrong for coming up with a better regex than mine, which assumed that the use statement would necessarily end with a semicolon.

Genealogy, web services and Perl

February 7, 2008 Community 1 comment

FamilySearch, the world’s largest repository of genealogical resources, announced its 2008 FamilySearch Developers Conference.

The newly released FamilySearch Family Tree API and soon-­to-­be-­released
Record Search API will be main topics of discussion. Other popular topics will be how to read, write, combine, separate, and synchronize with new FamilySearch online resources, developer keys, tree cleaning,
GEDCOM, and PAF.

Genealogy these days is all about lots of data mangling, web services, big databases: it’s an ideal area for Perl to work in. Paul Johnson’s Gedcom module has long been used to handle GEDCOM files, the standard interchange format for genealogical data.

I chatted with Pat Eyler about the FamilySearch project, of which he’s a member:

“World’s largest repository of genealogical resources” only tells part of the story. Imagine this:

  1. all of the microfilmed genealogical records that the LDS church owns made freely available
  2. a framework for indexing these (or any other genealogical images someone wants to donate)
  3. a unified database of individuals and relationships with varying levels of access control, available to anyone through a rich web client or through web services

Billions of names, petabytes of image data, and the tools to access and use all of it.

There’s quite a bit of data here for the examining. Even if you’re not interested in the conference, check out what’s going on with the data. It seems to be an ideal dovetail with the open source community.