You can convert your data via something like:

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; }
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.

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:

$out->@{ keys $in->{$attrib}->% }-->{$attrib}= values $in->{$attrib}->%;
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.)

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.