I think the module Storable can be of help, It has the methods 'store' and 'retrieve' which are direct to work with when storing datastructures to files and returning them back,in addition to other utilities, check the link above...In my Windoze Machine, the DB_File module did not really work for me, so I used this one instead...
use strict; use warnings; use Storable; my %hash; $hash{"Janet Jones"} = { "spouse" => "Bob Jones", "son 1" => "Tom Jones", "son 2" => "Pete Jones", "pet 1" => "Boyle", "father" => "Richard Smith", "mother" => "Fran Smith", "sister 1" => "Louise Williams", "address" => "1 Main St, Littleton, PA, 55555", }; $hash{"Bob Jones"} = { "spouse" => "Janet Jones", "son 1" => "Tom Jones", "son 2" => "Pete Jones", "pet 1" => "Boyle", "father" => "Paul Jones", "mother" => "Stella Jones", "brother 1" => "Paul Jones, Jr", "brother 2" => "Vince Jones", "brother 3" => "Dan Jones", "sister 1" => "Andrea Limux", "address" => "1 Main St, Littleton, PA, 55555", }; store(\%hash, "HashOfHashesFile.txt"); my %friends = %{retrieve("HashOfHashesFile.txt") }; for my $name (keys %friends){ print "$name->\n"; for my $info(keys %{$friends{$name}}){ print " " x length("$name"); print "$info-> $friends{$name}{$info}\n"; } }
OUTPUT:
Janet Jones-> spouse-> Bob Jones son 1-> Tom Jones pet 1-> Boyle mother-> Fran Smith father-> Richard Smith address-> 1 Main St, Littleton, PA, 55555 son 2-> Pete Jones sister 1-> Louise Williams Bob Jones-> spouse-> Janet Jones son 1-> Tom Jones brother 3-> Dan Jones pet 1-> Boyle mother-> Stella Jones brother 2-> Vince Jones father-> Paul Jones brother 1-> Paul Jones, Jr address-> 1 Main St, Littleton, PA, 55555 sister 1-> Andrea Limux son 2-> Pete Jones
This link to a Wikipedia article is very informative of the concept of data serialization..


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

In reply to Re: Can I tie a hash of hashes to a file? by biohisham
in thread Can I tie a hash of hashes to a file? by r1n0

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.