Arrays vs. Lists in Perl: What's the Difference?

| No Comments | No TrackBacks

One of the most common sources of confusion for new Perl programmers is the difference between arrays and lists. Although they sometimes look similar, they are very different things, and many bugs and misunderstandings are caused by not having a full understanding of the differences. Even experienced Perl programmers sometimes think arrays and lists are the same, but they are quite different in several important ways.

Here's a table which outlines some of the differences. Each of these differences is discussed in detail below.

...are variables....are ephemeral.
...can be changed....are immutable.
...can be named or anonymous....never have names.
...use the sigil not have sigils.
...can be referenced....distribute references.
...can not be passed to or returned from subroutines....are the only thing passed to and returned from subroutines.
...can be multidimensional....are always one-dimensional.
...have known behavior in scalar not exist in scalar context.

MongoDB Driver 0.502 Released

| No Comments | No TrackBacks

I'm happy to announce the release of the latest version of the Perl MongoDB driver. This version has a number of significant changes, including the new MongoClient top-level API. This change unifies the API nomenclature among most of MongoDB's officially supported driver libraries. It is also now the default behavior for MongoDB drivers to issue a write concern of 1 on all requests.

I'll be speaking on October 24th at MongoDB Boston 2012, taking place at the lovely Marriot Courtyard Tremont/Downtown.

Conference registration is a mere $100 ($30 for students). There are three tracks, covering everything from beginner topics presented by 10gen staff to advanced, detailed MongoDB presentations by industry leaders. Here's the abstract for my talk:

This talk introduces the features of MongoDB by demonstrating how one can build a simple library application. The talk will cover the basics of MongoDB's document model, query language, and API. In addition, we will learn how to use MongoDB within a typical web application framework.

If you're in Boston and you've never used MongoDB before, or are thinking of trying it out, I'd highly recommend stopping by. The demo application for the talk is written with Mojolicious::Lite and will soon be available on GitHub for you to experiment with.

Structured Data and the Road to Obsolescence

| 1 Comment | No TrackBacks

Starting with 0.46.3, MongoDB is no longer supported on Perl 5.8 and below. (If you must use 5.8, you can still use old versions of the driver, but you won't get any cool new features.) The first release of Perl 5.8 turned ten years old in July, so the fact that more and more of CPAN lists Perl 5.10 (or even 5.12) as a dependency should come as no shock. The current release of Perl is 5.16.

One of my many rules of software engineering, born of more than a decade seeing things done the Wrong Way, is that serialization must occur only at the extreme edges of your program. At all other points you should, if possible, deal only with structured data. The lack of it in one crucial area of the Perl MongoDB driver is what made support for Perl 5.8 no longer possible.

Toward a Unified libbson

| No Comments | No TrackBacks

BSON (binary JSON) is the data serialization format that MongoDB uses internally and over the network. It's a simple and expressive format which is easy to parse and efficient to store. When BSON documents are retrieved from the MongoDB store, they must be deserialized by the client-side driver code and inflated into the native structures of the programming language being used. Unfortunately, this has resulted in a great deal of code duplication, as each language driver has implemented its own BSON encoder and decoder, sometimes on multiple occasions.

Fast datetimes in MongoDB

| No Comments | No TrackBacks

One of the most common complaints about the Perl MongoDB driver is that it tries to be a little too clever. In the current production release of (version 0.46.2 as of this writing), all datetime values retrieved by a query are automatically instantiated as DateTime objects.

DateTime is a remarkable CPAN distribution. In fact, I would say that DateTime and its related distributions on CPAN comprise one of the best date and time manipulation libraries in any programming language. But that power comes with a cost. The DateTime codebase is large, and instantiating DateTime objects is expensive. The constructor performs a great deal of validation, and creates a large amouunt of metadata which is stored inside the object.

Upcoming changes to the Perl MongoDB driver solve this problem.

MongoDB 0.46.1 Released

| No Comments | No TrackBacks

I'm happy to announce that after a long delay, version 0.46.1 of the Perl MongoDB driver has now been uploaded to CPAN, and should be available on your friendly local CPAN mirror soon.

This release is mostly a series of minor fixes and housekeeping, in preparation for developing a more detailed roadmap for more frequent releases down the line. Here's what's new so far:

Two new Pod::Weaver Plugins

| No Comments | No TrackBacks

After falling in love with Pod::Weaver, I've released two new Pod::Weaver plugins which you may find useful for assembling boilerplate POD sections in your distributions.

The first is Pod::Weaver::Section::Extends which will add a =head1 EXTENDS section with a list of everything in your @ISA at compile-time. It should work with any kind of object that modifies @ISA in a normal way.

The second is Pod::Weaver::Section::Consumes, which does the same thing for Moose roles. It will interrogate any Moose-compatible meta object for your class to find a list of roles.

The repositories for them are here and here.


Falling in love with Pod::Weaver

| No Comments | No TrackBacks

I've been working on Redis::Client for a while now. It's not ready for production use yet, and there's a lot of work yet to be done, but it's much better than anything else on CPAN right now for talking to Redis.

I hate boilerplate with a burning passion, and I will often go to extreme lengths to avoid typing it. (I typed it once already, dammit! Leave me alone!)

After having a great time learning to mess with Dist::Zilla, I decided to give another of Ricardo's projects, Pod::Weaver, a try. Here's the cool stuff I was able to do after not a lot of work.

Announcing namespace::sweep

| No Comments | No TrackBacks

A question recently appeared on Stack Overflow about using namespace::autoclean in conjunction with operator overloading.

It turns out that you can't, because namespace::autoclean, in addition to cleaning up symbols for imported subs, also cleans up the operator magic installed by

This had been noticed before, but the suggested fix was rejected in favor of implementing the logic to support overload methods in Class::MOP, which namespace::autoclean uses under the hood to figure out the list of allowed methods for a class, and it doesn't look like anyone is interested in doing that right now.

As it happens, I'm working on a distribution right now which uses Moose and does some operator overloading, so namespace::autoclean would be a problem. I decided that there's really no reason a symbol-cleaning pragma should depend on Moose (or the MOP) so I wrote namespace::sweep as a replacement. More on the advantages and disadvantages below.