Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: populating a HoA with regexp

by Athanasius (Archbishop)
on Aug 28, 2012 at 15:06 UTC ( [id://990261]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://990261]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found