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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.