Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Update:Made a minor correction to the code example. (Thanks Frodo72)
I've been finding myself building a lot of hashes of hashes of hashes ... of arbitrary depth lately, and i dont think my scheme is the greatest. So im wondering if somebody has a better scheme or if im on the right track.

Here's a simplified version of what i am basically doing:

use strict; use warnings; my %big_hoh; while ( my $data = get_one_record(...) ) { my @key_list = get_arbitrary_length_key_list($data, ...); my $last_key = pop @key_list; my $storage_point = \%big_hoh; foreach my $key (@key_list) { if ( ! exists $storage_point->{$key} ) { $storage_point->{$key} = {}; $storage_point = $storage_point->{$key}; } } $storage_point->{$last_key} = $data; }
This works but it seems pretty nasty to me. If $data were not a hashref, im not sure that it would work properly. I thought about building up from the back end, but that seems like it will be even worse.

This is for building a data cache for a system where users can do various searches in a MySQL DB, and sometimes it makes sense to cache some of the data, to take some load off the DB server. This is the 3rd major revision of the engine, and this revision is mostly optimizations.


In reply to Hash of Hash of Hash of ... by shemp

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (3)
    As of 2020-05-27 06:50 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      If programming languages were movie genres, Perl would be:















      Results (153 votes). Check out past polls.

      Notices?