Re: [MacPerl] how to grow a hash of hashes

[email protected] (Detlef Lindenthal) Sat, 30 Jul 2005 19:37:43 +0200
Newsgroups perl.macperl
Message-ID <[email protected]>
--------------010409060102090209000305
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

  ##  Bon jour.

  ##  Just for clarity: What is your distinction between "domain" and 
"name"?
  ##  "Domain" the first two levels, and the rest "name"??

  ##  Well, I thought it over; if you have just one hash entry
  ##      '64.207.97.183' => www.nigeria.gov.ng
  ##  and you put it into your hash:

$H{ '64.207.97.183'}{ng}{gov}{nigeria}{www}='is read';

  ##  then both the tests
 
print "www.nigeria.gov.ng\n" if exists $H{ 
'64.207.97.183'}{ng}{gov}{nigeria}{www};
print "nigeria.gov.ng\n"     if exists $H{'64.207.97.183' 
}{ng}{gov}{nigeria};

  ##  will be true, allthough you did not yet have an entry
  ##       '64.207.97.183' => nigeria.gov.ng   (without "www.")
print "----------------------------------\n";

  ##  And, even worse, if later you have this domain
  ##       '64.207.97.183' => nigeria.gov.ng   (without "www.")
  ##  and you enter it into your hash like this:
$H{ '64.207.97.183'}{ng}{gov}{nigeria}='is read';
  ##  then
print "www.nigeria.gov.ng\n" if exists $H{'64.207.97.183' 
}{ng}{gov}{nigeria}{www};
  ##  will no longer hold true.
print "----------------------------------\n";

  ###########################################
  ##  Try this, add a hash entry "{is_read}":

$H{'64.207.97.183'}{ng}{gov}{nigeria}{www}{is_read}=1;
$H{'64.207.97.183'}{ng}{gov}{nigeria}{is_read}=1;

  ##  If you test:

print     "nigeria.gov.ng\n" if exists 
$H{'64.207.97.183'}{ng}{gov}{nigeria}{is_read};
print "www.nigeria.gov.ng\n" if exists 
$H{'64.207.97.183'}{ng}{gov}{nigeria}{www}{is_read};

  ##  these tests work as desired.
  ##  Right?

  ##  And one remark:
  ##  To me it seems a good style to post such a task as a small typical 
perl script, maybe one can play around and test and solve the problem.

  ##  Au revoir,
  ##  Detlef


--------------010409060102090209000305--