I have a hash that holds for each record an anonymous hash with 2 elements: an array and a hash. I want to initialize this subsidiary hash with a list of keys.
I know hash slices can be used when you use a normal hash (not a ref) and use both a key list and values list.
My code is like this
my %records;
my $key = "key1";
my @states = ( "state1", "state2", "state3" );
$records{$key} = {
numbers => [],
states => %{@states} #This is wrong !
};
EDIT (marked as duplicate): This question asks how to add multiple keys to an anonymous hash.
my $states = { ... }; $records{$key} = { states => $states };states => { map { $_ => undef } @states }.%recordsto look like. It's puzzling that you have only keys for your hash and no values