[MacPerl] how to grow a hash of hashes
[email protected] (Louis Pouzin) Sat, 30 Jul 2005 18:41:35 +0200 (CEST)
| Newsgroups | perl.macperl |
|---|---|
| Message-ID | <[email protected]> |
Guten Tag,
and thanks for the response. Let me explain the context.
I have a plain text IPN archive. It contains about 7500 records and =
keeps growing. Each record is: IPN, name1, name2, etc. Some records =
contains several hundred names. I prefer to keep this archive as plain =
text for simplicity, and portability.
Every once or twice a day, I collect new IPN and names from raw text, =
email or others. It should not exceed a few dozens, or maybe a few =
hundreds if the collection has been suspended for a while.
And a few times a week I run an update of the archive. In case there are =
too many new records, I can split them in several batches.
Updating the archive consists in reading it sequentially, and matching =
its records against the new records:
For each archive record:
1- is the IPN in the new records ?
if so, what new names should be added to the IPN in the archive ?
2- if not, what domains (2 top levels) in the new records match those in =
the archive ? (for clustering)
It seems to me convenient to build a "new record" structure geared to =
provide answers to these questions. Hence the two hashes for names and =
domains. A hierarchical structure as you mentionned (64.207.97.183 > =
com > web-mania > server7) could work too, although I wonder if it =
would take a few more tests for matching names. E.g.
Archive contains: 64.207.97.183 nigeria.gov.ng
A new IPN comes with 64.207.97.183 www.nigeria.gov.ng
$ip =3D '64.207.97.183';
$H{$ip}{ng}{gov}{nigeria}{www}=3D'';
exists $H{$ip}{ng}{gov}{nigeria}; # is true,
but "nigeria.gov.ng" is not a name in the new IPN. We have to check keys =
at lower level to find out.
Anyway, whichever structure is used, it should allow for growing the =
lower level elements, since there may be several instances of an IPN in =
the new records.
It is trivial to grow a hash within a hash, e.g.
$H{$ip}{ng}{gov}{nigeria}{www}=3D'';
$H{$ip}{ng}{gov}{nigeria}{oil}=3D'';
but I don't know a way to grow a hash within an array, such as:
$H{$ip}[0]{$nam4}=3D''; or
$H{$ip}[0]=3D{$nam4,''};
Both constructions erase all previous keys in the hash. Is there another =
way ?
I could replace the array with a 2-key hash. Somewhat funny, but maybe a =
solution.
$H{$ip}{nam} =3D {$nam1,'',$nam2,'',$nam3,''};
$H{$ip}{dom} =3D {$dom1,'',$dom2,''}; # and later
$H{$ip}{nam}{$nam4}=3D''; # this works
Cheers
- -
On Sat, 30 Jul 2005 07:48:20 +0200, Detlef Lindenthal wrote:
>Your question is not clear to me.
To me it seems that you want to have a clear hierarchy:
IPN > 1st level domain > 2nd level domain > 3rd level
domain > ... nth level domain
e.g.
64.207.97.183 > com > web-mania > server7
And for this I would mould a hashes landscape. What is the difficulty?
BTW, do you have some hundred entries, or thousands of entries?
(If MacPerl hashes grow too big, they can become slow and malicious; so
one could prefer an SQL-solution.)