Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Re: descending a tree of hash references

by Amoe (Friar)
on Feb 20, 2002 at 12:35 UTC ( #146561=note: print w/replies, xml ) Need Help??

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.

my one true love

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

    Thanks, problem well stated. Unfortunately I couldn't reproduce the problem. I think you are not getting what you expect in $old when thawing. Try print Dumper($old) immediately after thawing.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://146561]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2016-10-22 00:29 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (291 votes). Check out past polls.