这是代码,它不起作用,我想做的是将哈希的哈希传递给子例程又名函数,但它给出了一些奇怪的输出。
my %file_attachments = (
'test1.zip' => { 'price' => '10.00', 'desc' => 'the 1st test'},
'test2.zip' => { 'price' => '12.00', 'desc' => 'the 2nd test'},
'test3.zip' => { 'price' => '13.00', 'desc' => 'the 3rd test'},
'test4.zip' => { 'price' => '14.00', 'desc' => 'the 4th test'}
);
my $a="test5.zip";
my $b="the 5th test";
$file_attachments{$a}->{'price'} = '18.00';
$file_attachments{$a}->{'desc'} =$b;
print(%file_attachments);
sub print{
my %file =@_;
foreach my $line (keys %file) {
print "$line: \n";
foreach my $elem (keys %{$file{$line}}) {
print " $elem: " . $file{$line}->{$elem} . "\n";
}
}
输出::::
test2.zipHASH(0x3a9c6c)test5.zipHASH(0x1c8b17c)test3.zipHASH(0x1c8b3dc)test1.zipHASH(0x3a9b1c)test4.zipHASH(0x1c8b5dc)