my %phrases = (
"phrase 1"=>{
qty=>1,
qtySum=>5,
qtyCont=>8
},
"phrase 2"=>{
qty=>10,
qtyCont=>34
},
"phrase 3"=>{qty=>1}
);
####
my %phrases = (
"phrase 1"=>{
qty=>1,
qtySum=>5,
qtyCont=>8,
qtyTotal=>\&qtyTotal
},
"phrase 2"=>{
qty=>10,
qtyCont=>34,
qtyTotal=>\&qtyTotal
},
"phrase 3"=>{
qty=>1,
qtyTotal=>\&qtyTotal
}
);
sub qtyTotal{
my $qty = 0;
my $key = #I don't know what to use
my $phObj = $phrases{$key};
foreach my $qType ('qty', 'qtySum', 'qtyCont'){
$qty += $phrases{$key}->{$qType} if exists $phrases{$key}->{$qType};
}
return $qty;
}
####
print "$phrases{'phrase 2'}->{'qtyTotal'}\n";