Using native Perl isn't "re-inventing wheels". Larry invented the wheels many years ago, your just using them.

Any api you or anyone devised to perform that operation would of necessity be either:

  1. So specific to that operation, that it would have no other use than that single operation.

    It would have to be called something like:

    sub createHoAoHfromAoHbyIndexingByTheValueOfOneKey{ my( $AoHref, $key ) = @_; ### About 20 lines of parameter checking and error reporting/excep +tion ### handling here. Because unlike doing it in-line, the programmer + writing ### this function cannot know what the caller will pass him. my %HoAoH; push @{ $HoAoH{ delete $_->{ $key } } }, $_ for @$AoHref; return \%HoAoH; }

    And to put that on CPAN, you'd need to wrap it in a package and add tests and documentation and dependencies and all bullshit--and how many times would it ever get used?

    And all of that to replace one, simple, long existing, simple, intuitive wheel.

    All it requires is for you to read the docs and apply a little thought; rather than expecting someone else to do your thinking for you.

  2. The only alternative would be some very generic, nested structure restructuring tool.

    Something that could equally be used to do:createAoHoAfromHoHoAbyTheValueOfOneKeyFromTheHashAndTheValueOfTheThirdElementOfTheSecondArray()

    And any API to do that kind of manipulation would have to be incredibly complex. Because it would essentially have to re-create all Perl's hash and array manipulation possibilities, without the benefit of Perl's very clear, concise and orthogonal syntax.

    And the complexity of any such undertaking would simply be ridiculous to the point of absurdity.

You're not trying to avoid "reinventing wheels", just avoid having to think!


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^3: remapping an arrayref of hashrefs to a hashref of array refs by BrowserUk
in thread remapping an arrayref of hashrefs to a hashref of array refs by metaperl

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.