oylee has asked for the wisdom of the Perl Monks concerning the following question:
and I thought that there has to be an easier way to cram that into a two-D array than the following code:August 2002 Mon Tue Wed Thu Fri Sat Sun 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#!/usr/bin/perl -w use strict; use Date::Calc qw(Calendar); sub parseCalendar { my ($year, $month) = ( scalar(@_) == 2 ) ? @_ : split(' ', `date +"%Y %m"`); my $cal = Calendar($year, $month); my @cal = split(/\n/, $cal); splice(@cal, 0, 3); # get rid of the first three lines (don't need + em); my @rv = map { $_ = substr($_, 1, length); [split /\s{4}|\s{2}/]; } @cal; return @rv; } my @cal = parseCalendar(); my $i = 1; foreach my $cal_line (@cal) { print "Week ", $i++, ":"; foreach my $day (@$cal_line) { $day ||= " "; print "$day "; } print "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Easier way to cram Date::Calc's Calendar into a 2-D array
by DamnDirtyApe (Curate) on Aug 07, 2002 at 18:44 UTC | |
by oylee (Pilgrim) on Aug 07, 2002 at 19:00 UTC | |
|
Re: Easier way to cram Date::Calc's Calendar into a 2-D array
by vek (Prior) on Aug 07, 2002 at 19:38 UTC |