The 2001 Perl Advent Calendar
[about] | [archives] | [contact] | [home]

On the 7th day of Advent my True Language brought to me..

Just like the vast majority of my programs start with use strict and use warnings, I tend to have a collection of standard extensions that I nearly always end up bringing in. In addition to those modules that I've mentioned in previous advent calendar days (Carp, File::Spec, Cwd, Data::Dumper) I always end up seem to bring in Scalar::Util.

The function that I tend to use most in Scalar::Util is blessed. It's yet another one of those functions that I could probably write myself. But why always reinvent the wheel? By bringing in blessed it's simpler, makes my code easier to read, and avoids me having to worry about annoying bugs and typos.

Another functionality in Scalar::Util that's really important is the weak referencing system. Since Perl currently uses a reference count garbage collector you can get yourself in an awful mess with circular referencing, and end up eating vast sums of memory - which is bad, M'kay. And here's a way out that's simple and straightforward, and again in a way where I don't have to worry about the details.

Wonderful. Extensions to perl like this remind me why I love the resilience and adaptiveness of Perl.