in reply to Can I tie a hash of hashes to a file?
OUTPUT: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"; } }
This link to a Wikipedia article is very informative of the concept of data serialization..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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can I tie a hash of hashes to a file?
by r1n0 (Beadle) on Nov 12, 2009 at 18:58 UTC |