Firstly, use the @ sigil for arrays. Secondly, string concatenation is not appropriate for arrays, use push instead. Here is a simplified solution.

johngg@shiraz:~/perl/Monks > perl -MData::Dumper -Mstrict -Mwarnings - +E ' my @AoH1 = ( { fruit => q{apple}, veg => q{pumpkin} }, { fruit => q{pear}, veg => q{swede} }, { fruit => q{cherry}, veg => q{pea} } ); my @AoH2 = ( { fruit => q{mango}, veg => q{cabbage} }, { fruit => q{plum}, veg => q{leek} }, ); my @megaAoH = (); push @megaAoH, @AoH1 if 1; push @megaAoH, @AoH2 if 1; print Data::Dumper->Dumpxs( [ \ @megaAoH ], [ qw{ *megaAoH } ] );' @megaAoH = ( { 'fruit' => 'apple', 'veg' => 'pumpkin' }, { 'veg' => 'swede', 'fruit' => 'pear' }, { 'fruit' => 'cherry', 'veg' => 'pea' }, { 'veg' => 'cabbage', 'fruit' => 'mango' }, { 'fruit' => 'plum', 'veg' => 'leek' } ); johngg@shiraz:~/perl/Monks >

I hope this is helpful.

Update: If you are actually using array references rather than arrays then square brackets should be used instead of parentheses and de-reference them for the push operation.

johngg@shiraz:~/perl/Monks > perl -MData::Dumper -Mstrict -Mwarnings - +E ' my $refToAoH1 = [ { fruit => q{apple}, veg => q{pumpkin} }, { fruit => q{pear}, veg => q{swede} }, { fruit => q{cherry}, veg => q{pea} } ]; my $refToAoH2 = [ { fruit => q{mango}, veg => q{cabbage} }, { fruit => q{plum}, veg => q{leek} }, ]; my $refTomegaAoH = []; push @{ $refTomegaAoH }, @{ $refToAoH1 } if 1; push @{ $refTomegaAoH }, @{ $refToAoH2 } if 1; print Data::Dumper->Dumpxs( [ $refTomegaAoH ], [ qw{ refTomegaAoH } ] +);' $refTomegaAoH = [ { 'fruit' => 'apple', 'veg' => 'pumpkin' }, { 'fruit' => 'pear', 'veg' => 'swede' }, { 'fruit' => 'cherry', 'veg' => 'pea' }, { 'fruit' => 'mango', 'veg' => 'cabbage' }, { 'veg' => 'leek', 'fruit' => 'plum' } ]; johngg@shiraz:~/perl/Monks >

Cheers,

JohnGG


In reply to Re: combining 3 arrays of hashes by johngg
in thread combining 3 arrays of hashes by pearlgirl

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.