Hello asqwerty, and welcome to the Monastery!

You already have the answer you were looking for. I just want to point out that the line:

%dfs = map {$_ => ()} @pref;

is incorrect. You can see this by printing the contents of %dfs (using Data::Dumper) immediately after that line:

$VAR1 = { 'brain' => 'lung', 'kidney' => undef };

When interpolated into an array or hash, the empty list () effectively disappears. I think you meant to write:

%dfs = map {$_ => []} @pref;

which works correctly, although

%dfs = map {$_ => undef} @pref;

also works.

Here is some good advice: Get into the habit of including the lines

use strict; use warnings;

at the head of every script. In this case, warnings would have shown you the problem:

Odd number of elements in hash assignment at ... line 6.

Hope that helps,

Athanasius <°(((><contra mundum


In reply to Re: populating a HoA with regexp by Athanasius
in thread populating a HoA with regexp by asqwerty

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.