NAME

Tie::Hash::Vivify - Create hashes that autovivify in interesting ways.

SYNOPSIS

use Tie::Hash::Vivify;

my $default = 0;
tie my %hash => 'Tie::Hash::Vivify', sub { "default" . $default++ };
print $hash{foo};   # default0
print $hash{bar};   # default1
print $hash{foo};   # default0
$hash{baz} = "hello";
print $hash{baz};   # hello

my $hashref = Tie::Hash::Vivify->new(sub { "default" });
$hashref->{foo};    # default
# ...

DESCRIPTION

This module implements a hash where if you read a key that doesn't exist, it will call a code reference to fill that slot with a value.

You can either tie to the Tie::Hash::Vivify package:

tie my %hash => 'Tie::Hash::Vivify', sub { "my default" };

Or you can create a new anonymous reference to a Tie::Hash::Vivify hash:

my $hashref = Tie::Hash::Vivify->new(sub { "my default" });

AUTHOR

Luke Palmer, lrpalmer gmail com

COPYRIGHT AND LICENSE

Copyright (C) 2005 by Luke Palmer

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.