The OP code prints a nice, simple calendar based on an array of arrays returned by Calendar::Simple->calendar(). There's one top-level array element for each week in the month, and each one holds a reference to an array of date numbers in that week (or undef for weekdays before the first and after the last day of the month).

If your question is "how do I flatten the AoA into a single array and convert the undef elements to empty strings?", then just loop through the "week" elements, pushing the days from each week onto a single array; here's a way to do that using "for" and "map":

use strict; use Calendar::Simple; use Data::Dumper qw/Dumper/; my ( $mon, $yr ) = ( localtime )[4,5]; $mon++; $yr+=1900; my @weeks = calendar( $mon, $yr ); my @month; for my $week ( @weeks ) { push @month, map { $_ || "" } @$week; } print Dumper( \@month );
Having done that, I have to wonder... Why would you want to do that?

(updated to include a link to the module's CPAN page)


In reply to Re: Calendar question by graff
in thread Calendar question by Aboveyou

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.