You can convert your data via something like:
I could factor that a little differently but I chose this way because I'm not assuming that all of your hashes actually do have the exact same keys and I didn't feel like checking that assumption.my $devs= hashjoin( { version=>\%vers, module=>\%mod, memory=>\%mem } ); sub hashjoin { my( $in )= @_; my $out= {}; for my $attrib ( keys %$in ) { for my $item ( keys %{ $in->{$attrib} } ) { $out->{$item}->{$attrib}= $in->{$attrib}->{$item}; } } return $out; }
Here is yet another case where I really want my "dereference an entire list at a time" operators. Then I could replace that middle loop with:
and it would make it easier for you to build your hashes this way from the beginning. (And, no, that last bit of code isn't valid Perl -- it is what I wish Perl supported: -->, ->%, ->@, ->@{}, ->@[], ->$, etc.)$out->@{ keys $in->{$attrib}->% }-->{$attrib}= values $in->{$attrib}->%;
I'd love to see an elegant method for generating the data in the format that merlyn suggested from the beginning, if each attribute is gathered from a different subroutine.
- tye (but my friends call me "Tye")In reply to (tye)Re: Hash Nightmare
by tye
in thread Hash Nightmare
by Limo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |