in reply to Re^3: How to create a hash whose values are undef?
in thread How to create a hash whose values are undef?

Great! I like your thinking, but you should be aware that "0" and even "" is not the same as "undef".
#!/usr/bin/perl -w use strict; use Data::Dumper; my @keys = (1,2,3); my %hash; @hash{@keys} = (undef) x @keys; print Dumper \%hash; __END__ Prints: $VAR1 = { '1' => undef, '3' => undef, '2' => undef };

Replies are listed 'Best First'.
Re^5: How to create a hash whose values are undef?
by cdarke (Prior) on Jul 07, 2009 at 07:36 UTC
    Exactly (that's why I said "some other value").
    Otherwise it could be done thus:
    my %hash; @hash{@keys} = undef;
    No need for the x operator. This sets the first value to undef, the others are unspecified so are set to undef as well.