Hi Monks. I am a very new to hashes in Perl. In the following code, I am creating a hash of hashes of arrays.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @array1 = ( "hello", "world" ); my @array2 = ( "here" ); my @array3 = ( "there" ); my %inner_hash = ( innerkey1 => \@array1, innerkey2 => \@array2, innerkey3 => \@array3 ); my %hash_of_hash_of_arrays = ( key => \%inner_hash ); print Dumper(\%hash_of_hash_of_arrays); exit(0);
This gives the output:
$VAR1 = { 'key' => { 'innerkey2' => [ 'here' ], 'innerkey3' => [ 'there' ], 'innerkey1' => [ 'hello', 'world' ] } };
Is there any way I can get this same output by defining only one variable? Something like:
my %hash_of_hash_of_arrays = { 'key' => { 'innerkey2' => [ 'here' ], 'innerkey3' => [ 'there' ], 'innerkey1' => [ 'hello', 'world' ] } };
...but that gives an error about "Reference found where even-sized list expected", and the output looks like:
$VAR1 = { 'HASH(0x57e1d78)' => undef };
which obviously is not what I want at all. Please help.

In reply to Creating a hash of hashes of arrays by estreb

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.