Hi Monks, I have two questions and I'd appreciate any sample code to solve it. I've used to store a large hash in the memory and since it is large I had to have more than 20-30 GB of ram to do it. Since I could access it I was running my code in this way. Now I want to convert my hash into database in the physical disc and then access it using sql/mysql queries whenever I want. I have this code to read my hash:
sub read_dict{ my $file=$_[0]; my $p=$_[1]; my $direction=$_[2]; my %dict1; open( FILE, "gunzip -c $file |") or die $!; # for each line of input file while (<FILE>) { chomp; local ($l1, $l2, $pr) = split /\|\|\|/; chomp ($l1, $l2,$pr); my @pr = split (/\s/,$pr); chomp $pr[1]; if ($direction) { if ($pr[3]>=$p) { $l1 =~ s/[[:punct:]]//g; $l1 =~ s/\s+/ /g; $l2 =~ s/[[:punct:]]//g; $l2 =~ s/\s+/ /g; $l2 =~ s/^\s+//; $l2 =~ s/\s+$//; $l1 =~ s/^\s+//; $l1 =~ s/\s+$//; chomp ($l1, $l2); if ($l2 && $l1) { push( @{$dict1{lc($l1)}}, lc($l2) );} }} else { if ($pr[1]>=$p) { $l1 =~ s/[[:punct:]]//g; $l1 =~ s/\s+/ /g; $l2 =~ s/[[:punct:]]//g; $l2 =~ s/\s+/ /g; $l2 =~ s/^\s+//; $l2 =~ s/\s+$//; $l1 =~ s/^\s+//; $l1 =~ s/\s+$//; chomp ($l1, $l2); if ($l2 && $l1) { push( @{$dict1{lc($l2)}}, lc($l1) );} }} } # return the hash of arrays!!! return \%dict1; }
This was the first part of the problem that I would like to store the hash line by line possibly in a database. Since, I'm not familiar with databases, you sample code would really help me.
Regarding the access to the hash I have such codes :
if (grep {$_ eq $string} @uniq_strings) { $match++ ; } #using hash elsif (exists $dict{$string}) { # loop over all elements in array of hash LOOP: foreach $element (@{$dict{$string}}) { if (grep {$_ eq $element} @uniq_strings) { $match++ ; last LOOP; } } }
Si I want to convert the dict search from hash to SQL format since it is the way to access database. I'd appreciate your helps.

In reply to storing a large hash in a database by Anonymous Monk

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.