1

レコード セット データを含むハッシュ参照の配列への参照を $record_sets として返す Amazon Perl モジュールを使用していますが、それを逆参照するのに苦労しています。データダンパーを使用してデータを印刷できますが、データを操作できる必要があります。以下は、モジュール用に提供されているドキュメントです

前もって感謝します:

#list_resource_record_sets
#Lists resource record sets for a hosted zone.
#Called in scalar context:

$record_sets = $r53->list_resource_record_sets(zone_id => '123ZONEID');

#Returns: A reference to an array of hash references, containing record set data. Example:

$record_sets = [
{
name => 'example.com.',
type => 'MX'
ttl => 86400,
records => [
'10 mail.example.com'
]
},
{
name => 'example.com.',
type => 'NS',
ttl => 172800,
records => [
'ns-001.awsdns-01.net.',
'ns-002.awsdns-02.net.',
'ns-003.awsdns-03.net.',
'ns-004.awsdns-04.net.'
]
4

2 に答える 2

4

$x = ['a','b','c'] などの配列参照がある場合、2 つの方法で逆参照できます。

print $x->[0]; # prints a
print $x->[1]; # prints b
print $x->[2]; # prints c

@y = @{$x}; # convert the array-ref to an array (copies the underlying array)
print $y[0]; # prints a
print $y[1]; # prints b
print $y[2]; # prints c

中括弧を使用することを除いて、ハッシュ参照は同じように機能します。例: $x = {a => 1, b => 2, c => 3}.

print $x->{a}; # prints 1
print $x->{b}; # prints 2
print $x->{c}; # prints 3

%y = %{$x}; # convert the hash-ref to a hash (copies the underlying hash)
print $y{a}; # prints 1
print $y{b}; # prints 2
print $y{c}; # prints 3

これをネストされた構造を持つ例に適用すると、これを行うことができます。

for my $x ( @{$record_sets} ) {
  print $x->{name}, "\n";
  print $x->{type}, "\n";

  for my $y ( @{$x->{records}} ) {
    print $y, "\n";
  }
}

# or something more direct
print $record_sets->[0]->{name}, "\n";
print $record_sets->[0]->{records}->[1], "\n";
于 2012-10-05T21:39:59.273 に答える
0

$record_sets は配列参照です。それを逆参照するには、次を使用できます

my @array = @{ $record_sets };

各レコード セットはハッシュ リファレンスです。

for my $record_set ( @{ $record_sets } ) {
    my $set = %{ $record_set };
}

たとえば、名前とレコードを取得するには (配列リファレンス):

for my $record_set ( @{ $record_sets } ) {
    print $record_set->{name},
          ': ',
          join ', ', @{ $record_set->{records} };
    print "\n";
}
于 2012-10-05T21:36:20.790 に答える