in reply to Re^2: hash keys compare
in thread hash keys compare
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:
|
---|