The expected structure doesn't make any sense, have you tried to populate a hash by it and use
Data::Dumper to visualise it?
Odd number of elements in hash assignment at ...line 29.
$VAR1 = {
'HASH(0x563b633597c8)' => undef,
'RED' => {
'PRICE' => 0,
'CODE' => 'code value 1',
'LABEL' => 'RED'
},
'HASH(0x563b63359750)' => 'BLUE'
};
You can't assing two values to a single key.
If you want to assign an array reference to each key, though, it's doable:
#!/usr/bin/perl
use warnings;
use strict;
use Test::More;
my %in = ( 1 => { PRICE => 0,
CODE => 'code value 1',
LABEL => 'RED' },
2 => { PRICE => 0,
CODE => 'code value 2',
LABEL => 'RED' },
3 => { PRICE => 1,
CODE => 'code value 3',
LABEL => 'BLUE' } );
my %out;
push @{ $out{ $_->{LABEL} } }, $_ for values %in;
is_deeply \%out, {
RED => [
{ PRICE => 0,
CODE => 'code value 1',
LABEL => 'RED' },
{ PRICE => 0,
CODE => 'code value 2',
LABEL => 'RED',} ],
BLUE => [ {
PRICE => 1,
CODE => 'code value 3',
LABEL => 'BLUE',
} ],
}, 'same';
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]