Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: varying length multi-dimensional hashes

by chromatic (Archbishop)
on Oct 04, 2000 at 22:20 UTC ( #35305=note: print w/replies, xml ) Need Help??


in reply to varying length multi-dimensional hashes

So what you need is an arbitrarily nested hash searcher? Yikes, those can get tricky. See ref, but I'd start out with (pseudo) code like the following:
sub find_value { my $hash_ref = shift; my $level; foreach my $key (keys %$hash_ref) { $level .= "$key\n"; my $value = $hash_ref->{$key}; if (ref($value) eq 'HASH') { $level .= find_value($value); } else { $level .= "\t$value\n"; } } return $level; }
That's untested, and it doesn't do anything that Data::Dumper doesn't do better... but it's a place to start.

Replies are listed 'Best First'.
RE: Re: varying length multi-dimensional hashes
by joe (Acolyte) on Oct 04, 2000 at 22:42 UTC
    Thanks Chromatic! That looks like the exact answer for traversing the hash. Now all I need is to do is to figure out how to create the hash. My partner suggests using eval. What do you think?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://35305]
help
Chatterbox?
[BarApp]: I can not use modules. I gain temporary access and still can not use modules.
[Cosmic37]: ta erix - this szabo geezer is pretty cool methinks and he writes about undef but I cannot see instructions for redefining the record separator after having undefined it
[Corion]: $/ = "wahtever";
[Corion]: (it's a magic variable)
[karlgoethebier]: BarApp: whoami
[Cosmic37]: ok fankyou - I was wondering about that but thought there might be a redefine command or something; peachy
[Lotus1]: Cosmic37 if you undef $/ in a local context to a block it won't affect the global version after the block finishes
[Lotus1]: or you can just do local $/ in a block

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2017-06-29 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (672 votes). Check out past polls.