Hi,

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
Sunday0,01,02,03,0 4,0
Monday0,11,12,13,1 4,1
Tuesday0,21,22,2
Wednesday0,3
Thursday0,4
Friday0,5
Saturday0,6
Total0,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

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.