One possible solution only briefly tested under the debugger:
DB<1> @keylist = qw/one two three four/; DB<2> $hash = (); DB<3> sub make_hash {$string = join '}{', @_ ; $string = '$hash{' +. $string . '} = 0'; eval $string;} DB<4> make_hash(@keylist); DB<5> x \%hash; 0 HASH(0x6004f9dc0) 'one' => HASH(0x6004f9d48) 'two' => HASH(0x6004f9c10) 'three' => HASH(0x6004f9be0) 'four' => 0 DB<6> make_hash( qw/jan feb mar apr may jun/) DB<7> x \%hash; 0 HASH(0x6004f9dc0) 'jan' => HASH(0x60064b430) 'feb' => HASH(0x60064b508) 'mar' => HASH(0x60064b538) 'apr' => HASH(0x600500860) 'may' => HASH(0x60064eab0) 'jun' => 0 'one' => HASH(0x6004f9f58) 'two' => HASH(0x600639458) 'three' => HASH(0x6006175e8) 'four' => 0
I did not try further, but it appears to work. One thing missing is the check of the eval return value, but this was just a kind of quick proof of concept. Passing additional arguments such as an hash ref and the value to be assigned, rather than hardcoding them, seems to be an implementation details.

In reply to Re: define a hash-value, using hash-ref and a list of keys by Laurent_R
in thread define a hash-value, using hash-ref and a list of keys by janssene

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.