in reply to Re: descending a tree of hash references
in thread descending a tree of hash references
Hey YuckFoo. Ready for context? Here goes...
I'm getting a hashref from a DB_File, and unfreezing the data structure contained within with Storable. Then I traverse a user-defined path in the hashref and set a key in it, and it'll eventually get frozen back to the DB_File. An added complication (one that I should have mentioned, with hindsight :() is that if the full path doesn't exist, I have to create all the hashrefs leading up to the end - whilst still preserving everything that was in the original data structure. Here's a literal chunk of code from what I have.
# the first element of $path is always a key in the DB_File my ($root, $tip) = (shift(@path), pop(@path)); # get old tree my $old = thaw($db{$root}); # start off at the root $nodule = $old; while (my $next_key = shift @path) { unless (exists $nodule->{$next_key}) { $nodule->{$next_key} = {}; } $nodule = $nodule->{$next_key}; } $nodule->{$tip} = $content; print Dumper($old);
The thing is, when I print $old with Data::Dumper, I would expect it to be a structure looking like this (given that @path = ('foo', 'bar'), $tip = 'baz' and $content = 'some arbitrary data'):
$VAR1 = {foo => {bar => {baz => 'some arbitrary data'} } };
Instead it looks like:
$VAR1 = undef;So that's what I want to achieve, and the example I gave in the question seems to be lose context in this environment, when by all rights it should work. Damn real life.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: descending a tree of hash references
by YuckFoo (Abbot) on Feb 20, 2002 at 20:10 UTC |