Reference to Anonymous Hash

前端之家收集整理的这篇文章主要介绍了Reference to Anonymous Hash前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_301_1@

对匿名哈希的创建与使用
#!/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

猜你在找的Perl相关文章