Perhaps you are looking for:

use strict; use warnings; use Data::Dump::Streamer; my @ranges = ( [ { I => 3, }, { I => 4, }, { I => 2, }, { I => 6, }, { I => 9, }, ], [ { I => 3, J => 2, }, { I => 4, J => 3, }, { I => 3, J => 4, }, { I => 3, J => 6, }, { I => 4, J => 0, }, { I => 4, J => 1, }, ], [ { I => 4, J => 3, K => 2, }, { I => 4, J => 3, K => 1, }, { I => 4, J => 2, K => 2, }, { I => 2, J => 3, K => 2, }, { I => 6, J => 2, K => 1, }, ], ); my $loop =0; foreach my $rngGrp (@ranges) { my @ds; my $f=0; foreach my $rngHash (@$rngGrp) { my @rngList = sort keys %$rngHash; insert (\@ds, $rngHash, \@rngList, "line $f"); $f++; } if ( $loop == 0 ) { insert (\@ds, undef, [6], "new line"); insert (\@ds, undef, [9], "new line"); } elsif ( $loop == 1 ) { insert (\@ds, undef, [4, 0], "new line"); insert (\@ds, undef, [3, 6], "newer line"); } elsif ( $loop == 2 ) { insert (\@ds, undef, [2, 3, 2], "new line"); insert (\@ds, undef, [6, 2, 1], "newer line"); } $loop++; Dump (\@ds); print "\n\n"; } exit; sub insert { my ($array, $hash, $keys, $text, $dim) = @_; $dim ||= 0; if (! defined $hash) { if ($#$keys > $dim) { $array->[$keys->[$dim]] ||= []; insert ($array->[$keys->[$dim]], $hash, $keys, $text, $dim + + 1); } else { $array->[$keys->[$dim]] = $text; } return; } if ($#$keys > $dim) { $array->[$hash->{$keys->[$dim]}] ||= []; insert ($array->[$hash->{$keys->[$dim]}], $hash, $keys, $text, + $dim + 1); } else { $array->[$hash->{$keys->[$dim]}] = $text; } }

Prints:

$ARRAY1 = [ ( undef ) x 2, 'line 2', 'line 0', 'line 1', undef, 'new line', ( undef ) x 2, 'new line' ]; $ARRAY1 = [ ( undef ) x 3, [ ( undef ) x 2, 'line 0', undef, 'line 2', undef, 'newer line' ], [ 'new line', 'line 5', undef, 'line 1' ] ]; $ARRAY1 = [ ( undef ) x 2, [ ( undef ) x 3, [ ( undef ) x 2, 'new line' ] ], undef, [ ( undef ) x 2, [ ( undef ) x 2, 'line 2' ], [ undef, 'line 1', 'line 0' ] ], undef, [ ( undef ) x 2, [ undef, 'newer line' ] ] ];

DWIM is Perl's answer to Gödel

In reply to Re: incremental additions to multidimensional arrays by GrandFather
in thread incremental additions to multidimensional arrays by Anonymous Monk

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.