I'm working with a complex data structure that looks like this:
$data[1]->{'477'}->[5] = [ 'value', 'value', 0 , undef, 5, 'value' ];
The code was working quite nicely until I started working with very large data sets that caused my machine to run out of memory. To get around this problem, I'm trying to use a disk-based tied data structure with MLDBM. Unfortunately, I can't get it to work. Here is some simplified code:
use MLDBM qw(DB_File Storable); # ... stuff .... foreach $gid (@group_ids) { my %temp_hash; unlink "$DBFilePath/$$.$gid" if -e "$DBFilePath/$$.$gid"; tie %temp_hash, 'MLDBM', "$DBFilePath/$$.$gid", O_RDWR|O_CREAT, 06 +40 or die "Can't tie temp_array to $DBFilePath/$$.$gid: $!"; $data[$gid] = \%temp_hash; foreach $sample_id (@{$groups[$gid]}) { foreach $element_num ( 0 .. $element_count ) { $element = []; # ... do a bunch of stuff here ... $data[$gid]->{$sample_id}->[$element_num] = $element; } } }
Unfortunately, that assignment at the end doesn't take, and $data[$id] remains empty. I've tried things like this:
$tmp = $data[$gid]->{$sample_id}; $tmp->[$element_num] = $element;
But that still doesn't work. The only way I've found to add anything to $data[$id] is to assign an array ref in its entirety:
$tmp = $data[$gid]; $tmp=>{$sample_id} = [ $element1, $element2, ... ];
That is obviously not a workable solution, since I need to add elements one by one to get around the memory issues. Am I asking for too much or am I just doing this wrong? Thanks!

In reply to Need help with complex tied data structure by genecutl

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.