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

On the 16th day of Advent my True Language brought to me..
Tie::Hash::Cannabinol

Returning once again to the silly, this day's module is a toy example of tieing to hashes. The actual problem space isn't useful at all (well, apart to remind you all that drugs are bad, M'kay.) Here the actual code is worth a look for anyone wanting to learn how tieing works. In my Wax::On Wax::Off talk I stipulated that the only effective way to get new concepts to stick is for the demonstrator to latch them onto memorable concepts so that they'll less likely to be forgotten. Dave has certainly picked a memorable subject and humorous effect for his module.

The code started out from a

  • perl.com article
  • that Dave Cross wrote that explains how hash tieing works. Since then Dave has updated it as perl has gone along. Most recently perl has gained the ability, though the Attributes::Handlers interface, to tie new variables to classes via an attribute. Dave has updated the module to provide an example of the new (super easy) interface.

  • perltie
  • Attribute::Handlers
  • The perl.com article