in reply to How to create a hash whose values are undef?

Assuming your keys are in @keys:
my %hash; @hash{@keys} = ();

Replies are listed 'Best First'.
Re^2: How to create a hash whose values are undef?
by Anonymous Monk on Jul 06, 2009 at 02:59 UTC
    But what if I want @keys to be the keys in a second-level hash, like so:

    $hash = {'foo' => { 'key1 => undef, 'key2' => undef, ...
    I am using a hash ref here, but I don't think that should make too much of a difference.