Hi ikegami,

Thank you. After reading your post my decision is to not pre-allocate the array and I have decided on using an array of hashes.

In the loop section where I am using the array and hash could you tell me if the hash 'dayHash' filled and pushed onto the @summary array for $wk=0 is different than the 'dayHash' pushed onto the @summary array for $wk=1? Said differently, am I saving a copy of the hash keys and values into the array or am I saving the same reference to the same hash in every element of the array and overwriting the hash values each time with the next week's order totals from %total_opd?

Thanks.

RF

# create data for small summary table of all retailers my $numWks = (($num_days - ( 7 - $firstDOW_curMonth )) / 7 ) + 1; if ( (($num_days - ( 7 - $firstDOW_curMonth )) % 7 ) ) { $numWks++; } my %dayHash; # the hash my @summary; # the array of hashes # init the blank portion of $summary[][] if there is one #my $temp = 0; #while ( $temp < $firstDOW_curMonth ) { # $summary[0][$temp++] #} my $wktotal; my $count=1; # key into %total_opd, it is based on date (1-$numdays) my $firstDOW = $firstDOW_curMonth; # $wk is index for array for ( my $wk = 0; $wk < $numwks; $wk++ ) { $wktotal = 0; # the first time through $dw may be 0, 1, 2,...6 # $dw is the key of the hash for ( my $dw = $firstDOW; $dw < 7; $dw++ ) { $dayHash{$dw} = $total_opd{$count}; $wktotal += $total_opd{$count}; last if ($count++ == $num_days); } $firstDOW = 0; # next time through the $dw loop it will start a +t 0 $dayHash{7} = $wktotal; # save the accumulated total for the we +ek push @summary, $dayHash; # last if ($count > num_days); }

In reply to Re^2: pre-size a two-dimensional array by rightfield
in thread pre-size a two-dimensional array by rightfield

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.