Hash::Util's lock_keys

David Cantrell david at cantrell.org.uk
Wed Feb 19 14:04:41 GMT 2014


On Wed, Feb 19, 2014 at 02:51:09PM +0100, Abigail wrote:

> I've been wondering about how easily people resort to storing data in
> hashes, using string literals as keys, while they cry foul if they ever
> saw a program not using strict. Specially when it comes to traditional
> Perl objects, who store their entire state in a hash, and none in a
> lexical variable. [1]
> 
> Even without strict, typos in variables at least warn (assuming warnings
> are on), while typos in string literals at best give you a run time
> error or warning.

This is why I like using Tie::Hash::Vivify:

my $hash = Tie::Hash::Vivify->new(sub {
    confess("No auto-vivifying\n".Dumper(\@_));
});

It's still a run-time error, but at least it's a nice obvious run-time
error.  But I confess to not basing my objects on it. I suppose I could,
because re-blessing tied objects does leave the tie() magic intact.

-- 
David Cantrell | Cake Smuggler Extraordinaire

          All praise the Sun God
          For He is a Fun God
          Ra Ra Ra!


More information about the london.pm mailing list