Hi Monks
I'm enjoying you wisdom for quite some time now
and first of all I wanted to thank you for making my life easier and me a better perl user!

Now I ran into a problem I just can't figure out and hope you can again share your wisdom with me.

In my current script I am building an IntervalTree with the
package Set::IntervalTree of a file containing genomic
coordinates together with some other info I want to retrieve for coordinate ranges.

This works just perfect and does what I need, but now I
would like to store the built tree to disk and retrieve
it later on so that I do not have to rebuild it every
time I search for coordinates.
I used Storable already in several scripts and thought it
would be a great idea to do so again, from what I have
read in your great Object Serialization Basics this looked very promising.

So I create a hash of trees for each chromosome that is
found in my input file like this

while (<FILE>){ my @line = split (/\t/,$_); ## tab separated file my @tmp = split(/\./,$line[1]); ## chromosome name in field 2, as +part of a dot separated string $chr{"$tmp[1]"} = new Set::IntervalTree() unless (defined $chr{"$ +tmp[1]"}); $chr{"$tmp[1]"} -> insert($count,$line[2]-1,$line[3]+1); ## fields + 3 and 4 contain the coordinates, -1 and +1 to allow search for direc +t overlaps at start and end }

which works fine, then I store this hash using Storable
store (\%chr, "$file.coordinates") or die "Can't store %chr in file.co +ordinates!\n";

In a second run I check for the presence of this file and
if it exists I try to retrieve it via
my $hashref; %chr = %{$hashref = retrieve("$file.coordinates")};

But when I later on try to access coordinates in this
deserialized hash I get a segmentation fault.
I guess the problem is that I would to somehow create a
new IntervalTree object first and just fill it with the
contents from disk but I just can't figure out how.

I hope you can understand the problem from the bit of code I post.
Your help is much appreciated, thank you for your time!


In reply to Storing and retrieving a hash of objects by Frnak

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.