I'm writing some functions to work with the data and reading the hash and just particular branches of keys has not been a problem. But I'd like to be able to arbitarily create a branch in this data structure based on a reference to a point in it. So for example, I'd like to be able to do:$DATA{1}{a}{e} = 'snu'; $DATA{2}{a}{f} = 'woo'; $DATA{3}{b} = 'foo'; $DATA{4}{a}{e} = 'bar'; $DATA{5}{d} = 'bop';
Which would in effect create the following:put_element($DATA{3}, 'h', 'i', 'worked');
This function would be useful in culling and replacing brances of the data structure, and so on. But, alas, I am having issues. After I call the function that I have written, and then walk the subsiquent hash, it only contains the original seeded values, and not the one I added with my function. I can't figure out what is wrong, or more importantly, how to make it do what I would like. The function, as I have written it, is as follows:$DATA{3}{h}{i} = 'worked';
Any input into where my errors may be is appreciated.sub put_element { my $current = shift || die("Need root hash reference for put_element +!"); # reference to the current level my $value = pop || die("Need value to be put for put_element!"); + # value to be placed in structure $current = $$current{shift(@_)} while (@_ > 0); ${$current} = $value; return 1; }
Thanks,
Scott
In reply to Missing something with regards to references by scottb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |