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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.