On Mon, Mar 02, 2009 at 09:17:22AM +0100, Johan Vromans wrote:
> David Cantrell <da...@cantrell.org.uk> writes:
> > Tie::Hash::Vivify is useful for detecting this:
> > my $hashref = Tie::Hash::Vivify->new(sub {
> >     confess("No auto-vivifying (did you mis-spell 
> > something?)\n".Dumper(\...@_))
> > });
> What's wrong with lock_keys from Hash::Util?

Two things.

First, I didn't think to look there.

Second, it doesn't appear to do the same thing.  The way I'm using it,
Tie::Hash::Vivify prevents me from accidentally auto-vivifying a key by
trying to retrieve a value that doesn't exist.  lock_keys would appear
to prevent me from doing something like:

  foreach(@blah) {
      $hash{$_} = ...
  }

unless I know all the possible keys in advance.  Now, in the case I
cut n pasted my example from, I *do* know them all in advance, while in
the general case you don't, but preventing accidental auto-vivification
is still a Good Thing.

-- 
David Cantrell | A machine for turning tea into grumpiness

EIN KIRCHE! EIN KREDO! EIN PAPST!

Reply via email to