package MultiHash; sub TIEHASH { my ($class) = map { ref || $_ } shift; my $level = shift || 0; return bless { level => $level, data => {}, }, $class; } sub FETCH { my $self = shift; my $key = shift; if( UNIVERSAL::isa( $self, 'HASH' )) { print "($self) fetching '$key': $self->{ data }{ $key }\n"; } else { print "($self) fetching '$key': $self->{ data }{ $key }\n"; } return $self->{ data }{ $key }; } sub STORE { my $self = shift; my $key = shift; my $value = shift; RECURSE_CASE: { # ===== MULTIDIMENSIONAL HASH if( UNIVERSAL::isa( $value, 'HASH' )) { if( exists $self->{ data }{ $key } ) { $self->{ data }{ $key } = $value; print "($self) storing '$value' into '$key'\n"; } else { my $node; tie %$node, "MultiHash"; $self->{ data }{ $key } = $node; print "($self) storing '$value' into '$key' with new node\n"; } last RECURSE_CASE; } if( UNIVERSAL::isa( $value, 'MultiHash' )) { if( exists $self->{ data }{ $key } ) { $self->{ data }{ $key } = $value; print "($self) storing '$value' into '$key'\n"; } else { my $node; tie %$node, "MultiHash"; $self->{ data }{ $key } = $node; print "($self) storing '$value' into '$key' with new node\n"; } last RECURSE_CASE; } if( UNIVERSAL::isa( $value, 'SCALAR' )) { $self->{ data }; last RECURSE_CASE; } } return $value; } sub DELETE { my $self = shift; my $key = shift } sub FIRSTKEY { my $self = shift; my $temp = keys %{ $self->{ data }}; return scalar each %{ $self->{ data }}; } sub NEXTKEY { my $self = shift; return scalar each %{ $self->{ data }}; } 1;