hi Super doc,
What I am trying to explain is that the list of keys in $c in hash1 should be exactly similar to list of keys in $f in hash2. I just want a list of keys that are not present in either of them. For ex:
html
$a = 'a, b , c , d, e, f';
$f = 'a, 1, c, d, 2, , f';
SO I want a report saying :
$a is missing keys "1, 2".
$f is missing keys "b, e".
/html
The hash that you used to explain works fine for simple hash tables with one key and one value.
I am not sure how to build a data structure, for a hash like this one:
html
$hash1->{$a}{$b}{$c}
$hash2->{$d}{$e}{$f}
/html
Can you help me out? | [reply] |
oops... created a little too soon -- it's late.
I meant to say, See: perlref perlreftut perldsc to get you started.
(by the way -- the output of the print statement in the code above is fum.)
| [reply] [d/l] [select] |
I believe you are laboring under a misapprehension (or else I am).
You write of a "... list of keys in $f" and then give an example. Your example is not of a list, but of a string literal assigned to a scalar. A string literal can be used as a single key in a hash. Likewise, a scalar holding a string can be used as a single key in a hash. The two string literals given in your example are not the same, so they can be used as two keys in the same hash.
It is possible to ask questions about how similar or different two strings are and get useful answers, but you must first be very clear about just what similar and different mean in the context of your problem.
On The Other Hand...
If you just want to construct a nested data structure using hashes, you are almost there with the other example you give.
my $hash_reference = {}; # empty hash ref for now
my $a = 'fee';
my $b = 'fie';
my $c = 'foe';
$hash_reference->{$a}{$b}{$c} = 'fum';
# same as...
$hash_reference->{'fee'}{'fie'}{'foe'} = 'fum';
# same as...
$hash_reference->{fee}{fie}{foe} = 'fum';
print $hash_reference->{fee}{fie}{foe};
See: | [reply] [d/l] |