First, change @{$ns_records{$k}}->[$d] to $ns_records{$k}->[$d], and your warning goes away. You are trying to use an array as an arrayref, as the warning states. You wouldn't normally say "@array[0]" (that would be a slice). You would say "$array[0]". Dealing with references doesn't change how sigils are applied.
And here's another (and to me, clearer) way to build the datastructure.
use strict; use warnings; use Data::Dumper; my @ns_list = ( 'server1.foo-domain.net', 'server2.noo-domain.net', 'server3.zoo-domain.net', ); my @addr_list = ( '1.2.3.5', '11.22.33.55', '22.21.20.55', ); my @ptr_list = ( '5.3.2.1.in-addr.arpa', '55.33.22.11.in-addr.arpa', '55.20.21.22.in-addr.arpa', ); my @uptime_list = ( '131 days', '28 days', '366 days', ); my %hash; $hash{$ns_list[$_]} = [ $addr_list[$_], $ptr_list[$_], $uptime_list[$_] ] for 0 .. $#ns_list; print Dumper \%hash;
Dave
In reply to Re: Constructing a HoA from 4 separate arrays
by davido
in thread Constructing a HoA from 4 separate arrays
by hsinclai
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |