I am trying to create many hash references with identical contents. Using the x operator gives copies of the same reference. How can I get different references?
I need different references so that I can later update them independently of others.
My Code:
use strict;
use warnings;
use autodie;
use feature qw(say);
use open ':std', ':encoding(UTF-8)';
my %UNIT_COUNT = (
numsys => 6,
alg => 20,
geo => 15,
cogeo => 6,
trig => 12,
mensur => 10,
statprob => 11
);
my $out = [
map {
( { unit => $_, weight => 1 } ) x
( $UNIT_COUNT{$_} )
} keys %UNIT_COUNT
];
use Data::Dumper;
print Dumper($out);