in reply to Re: Hash to Hash to Hash ....
in thread Hash to Hash to Hash ....

Hi Me here again. Can't find the ref to 'auto vivification'. Still trying to find out more about it. Can you give me a brief run down.

I been using the set() function which works well. The next step is to add items into the tree. To do this I am using the same idea of passing a path. The question arises when passing a new path to a empty tree. i.e
set($ref_to_hash,1,(a c b d)) # set($hoh,$val, @path): ... by ariels sub set { my $hoh = shift; my $val = shift; my $last = pop @_; $hoh = $hoh->{$_} for (@_); $hoh->{$last} = $val }
the set function works if the 'a c b ' already exists. If it doesn't then we simply create a hash in space somewhere ( i think ). What I need is to dynamically create nodes which do no exist. I have done this by using a temporary hash to add the new item in and then link it back into the tree.
#create first node $hr=\%I; $hr->{'one'}=1; #create tmp node and link back in $new=\%tmp; $new->{'two'}=1; $hr->{'one'}=$new;
Seems to work ok but I reckon you'll have a better way Thanks again wert

Replies are listed 'Best First'.
Re: more Hash to Hash to Hash ....
by wertert (Sexton) on Aug 21, 2001 at 14:10 UTC
    just found out about auto autovivification. Seems to all tie together. The book says 'This is what happens when you try to assign through an undefined references and Perl automatically creates the reference you're trying to use.'