in reply to Using map to create a hash/bag from an array
The idiomatic way to do that in Perl is @hash{qw(a b c)} = (1) x 3;:
use strict; use warnings; use Data::Dumper; my %hash; @hash{qw(a b c)} = (1) x 3; print Dumper (\%hash);
Prints:
$VAR1 = { 'c' => 1, 'a' => 1, 'b' => 1 };
DWIM is Perl's answer to Gödel
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Using map to create a hash/bag from an array
by bart (Canon) on Dec 18, 2005 at 10:45 UTC | |
by GrandFather (Saint) on Dec 18, 2005 at 11:21 UTC |
In Section
Seekers of Perl Wisdom