in reply to use array for hash-keys without loop

my %hash; # Note: you cannot use 'my' on a slice @hash{@a} = (0) x @a; # Initialise values to zero @hash{@a} = undef; # No values @hash{@a} = @b; # Take values from @b

Replies are listed 'Best First'.
Re^2: use array for hash-keys without loop
by jwkrahn (Abbot) on Mar 11, 2010 at 12:56 UTC
    $ perl -le' use Data::Dumper; my @a = "A" .. "D"; my %hash; $hash{@a} = (0) x @a; print Dumper \%hash; ' $VAR1 = { '4' => '0000' };

    Oops!

      $hash{@a} = (0) x @a;

      Using @hash{@a} (as cdarke did) instead of $hash{@a} avoids the issue...

        He must have changed it after I posted because I copied and pasted that from his post.