in reply to Hash assignments using map

If you are trying to initialise a hash with four keys ("a" to "d") each with a value of 1 using map you need to pass your four keys into the map but pass eight things out the other side, 'a', 1, 'b', 1, 'c', 1, 'd', 1. This is because a hash with four key/value pairs will flatten to a list of eight elements. You can do it like this.

my @keys = qw{a b c d}; my %hash = map { $_ => 1 } @keys;

Your loop alternative could be written

my @keys = qw{a b c d}; my %hash; $hash{$_} ++ for @keys;

Another alternative is to use a hash slice

my @keys = qw{a b c d}; my %hash; @hash{@keys} = (1) x scalar @keys;

I hope this is of use.

Cheers,

JohnGG