对匿名哈希的创建与使用
#!/usr/bin/perl
use warnings;
use strict;
普通方法定义hash引用
my %gilligan_info = (
name => 'Gilligan',
hat => 'White',
shirt => 'Red',
position => 'First Mate',
);
my %shipper_info = (
name => 'Shipper',
hat => 'Black',
shirt => 'Blue',
position => 'Captain',
);
my @crew = (/%gilligan_info,/%shipper_info);
my $name = $crew[0]{'name'};
print $name."/n";
my @keys = keys %{$crew[0]};# attention to the dereference of the hash element of the array
print "@keys./n";
print $crew[1]->{'name'}."/n";
创建匿名hash表,注意书写方法
my @new_crew = (
{
name => 'Gilligan',
},
{
name => 'Skipper',
position => 'Caption',
);@keys = %{$new_crew[1]};print "@keys./n";本例结构引用自intermidiate perl
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。