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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.