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:


In reply to Re^3: hash keys compare by Anonymous Monk
in thread hash keys compare by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.