如何以垂直格式显示日历?

时间:2013-05-06 07:24:51

标签: perl

我需要以垂直格式显示日历;我怎么能得到这种格式?我尝试了一些perl脚本示例。

脚本:

  use strict;
  use Calendar::Simple;

  my @months = qw(January February March April May June July August
                  September October November December);

  my $mon = shift;
  my $yr  = shift;

  my @month = calendar($mon, $yr);

  print "\n$months[$mon -1] $yr\n\n";
  print "Su Mo Tu We Th Fr Sa\n";
  foreach (@month) {
    print map { $_ ? sprintf "%2d ", $_ : '   ' } @$_;
    print "\n";
  }

它可以作为横向格式的普通日历执行;如何更改为垂直格式...

需要输出为:

sun   1 5 6   
mon  2 3
wed ...
thu ...
fri ...
stu ... 

我是怎么做的......

1 个答案:

答案 0 :(得分:1)

我猜你只想在空白之前插入工作日,

更新:添加@ month2,转换@month

# ...
my @month = calendar($mon, $yr);
my @month2 = map {
  my $v=$_;
  [ map $_->[$v], @month ]
} 0..6;

my @wd = qw(Su Mo Tu We Th Fr Sa);
for my $i (0 .. $#month2) {

  my $el = $month2[$i];
  print $wd[$i], map {
    $_ ? sprintf("%2d ", $_) : "   ";
  }
  @$el;
  print "\n";
}