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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |