I wrote some pseudo code and when Perl-izing it I discovered I can't seem to do what I had planned the way I had planned. I do not use Pearl often so I was wondering if you could tell me how you usually save values in a two-dimensional array as I have not found any examples.
Below is the partly Perl-ized portion of code where I had expected to loop through the two dimensions of an array called @summary, the first dimension would represent the week-of-the-month and the second the day-of-the-week. The value to be put in each location was the total number of orders placed on a particular day (the %total_opd hash) with each row across showing the day of the week and the columns were how many weeks the month spanned (a month can span 4, 5, or 6 weeks). Below is kind of what the output would look like: 0,0 means week 1 (partials count) and the second 0 is for Sunday. Next would be 0,1 for week 1, day 1=Monday.
There may or may not still be other bugs but the real issue is how would I stuff the array?
Thanks.
RF
| wk1 | wk2 | wk3 | wk4 | wk5 | |
| Sunday | 0,0 | 1,0 | 2,0 | 3,0 | 4,0 |
| Monday | 0,1 | 1,1 | 2,1 | 3,1 | 4,1 |
| Tuesday | 0,2 | 1,2 | 2,2 | ||
| Wednesday | 0,3 | ||||
| Thursday | 0,4 | ||||
| Friday | 0,5 | ||||
| Saturday | 0,6 | ||||
| Total | 0,7 |
# 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 @summary[$numWks][7]; # !!! uh-oh this does not Perl-ize !!! # 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; my $firstDOW = $firstDOW_curMonth; for ( my $wk = 0; $wk < $numwks; $wk++ ) { $wktotal = 0; for ( my $dw = $firstDOW; $dw < 7; $dw++ ) { $summary[$wk][$dw] += $total_opd{$count}; $wktotal += $total_opd{$count}; last if ($count++ == $num_days); } $firstDOW = 0; $summary[$wk][$7] = $wktotal; last if ($count > $num_days); }
In reply to pre-size a two-dimensional array by rightfield
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |