in reply to Re^3: How to read Array
in thread How to read Array

Thanks, Yes I want all dns_record entries. In above example I need read all records for "A,NS,CNAME" records type "$json->{dns_zone}->{records}->{A}" I am trying use below script

$data = Cpanel::JSON::Load($json); my @dns_records; @dns_records = { map { $_->{dns_zone}->{records}->{A}->{dns_record}-> +{name} => $_->{dns_zone}->{records}->{A}->{dns_record}->{name} } @{$d +ata} };

Please guide what's wrong in my script

Replies are listed 'Best First'.
Re^5: How to read Array
by hdb (Monsignor) on Jul 09, 2013 at 13:57 UTC

    You are querying the wrong level of your structure. Compare to this

    my $output = to_json [ map { @$_ } values %{ (from_json $input)->{dns_ +zone}->{records} } ];

      I am new in Perl. I have trying to below query

      my $json = Cpanel::JSON::Dump( { 'dns_records' => [ map { ( { 'dns_rec +ord' => $_ } ) } @dns_record ] } );

      After that getting below array

      [{"dns_records": [ {"dns_record":{"ip":"192.64.179.9","ttl":"86400","name +":"86400","hostname":"192.64.179.10","type":"A"}}, {"dns_record":{"ip":"192.64.179.10","ttl":"14404","nam +e":"14400","hostname":"127.0.0.1","type":"A"}}, {"dns_record":{"ip":"@","ttl":"86400","name":"86400"," +hostname":"aresstest.com","type":"MX","mx_priority":"0"}}, {"dns_record":{"ip":"mail","ttl":"14400","name":"14401 +","hostname":"aresstest.com","type":"CNAME"}}, {"dns_record":{"ip":"www","ttl":"14400","name":"14402" +,"hostname":"aresstest.com","type":"CNAME"}}, {"dns_record":{"ip":"ftp","ttl":"14400","name":"14403" +,"hostname":"aresstest.com","type":"CNAME"}}]}]

      But I need below type of array

      [{"dns_record":{"ip":"192.64.179.9","ttl":"86400","name":"86400","host +name":"192.64.179.10","type":"A"}}, {"dns_record":{"ip":"192.64.179.10","ttl":"14404","nam +e":"14400","hostname":"127.0.0.1","type":"A"}}, {"dns_record":{"ip":"@","ttl":"86400","name":"86400"," +hostname":"aresstest.com","type":"MX","mx_priority":"0"}}, {"dns_record":{"ip":"mail","ttl":"14400","name":"14401 +","hostname":"aresstest.com","type":"CNAME"}}, {"dns_record":{"ip":"www","ttl":"14400","name":"14402" +,"hostname":"aresstest.com","type":"CNAME"}}, {"dns_record":{"ip":"ftp","ttl":"14400","name":"14403" +,"hostname":"aresstest.com","type":"CNAME"}}]

      Please guide.

        If you do not want to use my code, try (untested)

        my $json = Cpanel::JSON::Dump( map { ( { 'dns_record' => $_ } ) } @dns +_record );
Re^5: How to read Array (autoguidance)
by Anonymous Monk on Jul 09, 2013 at 10:52 UTC