Any perl expert can help me to understand this block of perl code
$a=18;
$b=55;
$c=16;
$d=88;
$mtk = {
'A' => [$a, $b],
'M' => [$c, $d]
};
is this dictionary hold char and pair and how to access key and values thanks a lot
Any perl expert can help me to understand this block of perl code
$a=18;
$b=55;
$c=16;
$d=88;
$mtk = {
'A' => [$a, $b],
'M' => [$c, $d]
};
is this dictionary hold char and pair and how to access key and values thanks a lot
$a, $b, $c, and $d are scalars. $mtk is a reference to a hash of arrayrefs. You can access it like:
print $mtk->{A}[0]; ## 18
I'd suggest the book Learning Perl if you are just getting started and struggling with this code.
This is a hash ref for array refs as values. Here is a traverse code below:
for my $key (sort keys %$mtk) {
print "Current key is $key\n";
for my $val (@{ $mtk->{$key} }) {
print "... and one of value is $val\n";
}
}
The output will be
Current key is A
... and one of value is 18
... and one of value is 55
Current key is M
... and one of value is 16
... and one of value is 88