1

我需要以垂直格式显示日历;我怎样才能得到这种格式?我尝试了一些示例 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 ... 

我如何做到这一点......

4

1 回答 1

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";
}
于 2013-05-06T07:42:50.640 回答