in reply to populating a HoA with regexp

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

Replies are listed 'Best First'.
Re^2: populating a HoA with regexp
by asqwerty (Acolyte) on Aug 28, 2012 at 15:24 UTC

    Thanks a lot!

    As you point out my code was wrong.