Advertisement
Guest User

new_year.pl

a guest
Dec 31st, 2010
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.46 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use DateTime;
  5. use utf8;
  6. use open qw/:std :utf8/;
  7.  
  8. print_month(2011, $_) for 1 .. 12;
  9.  
  10. exit 0;
  11.  
  12. sub print_month {
  13.     my ($year, $month) = @_;
  14.    
  15.     my @monthes = qw/Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь/;
  16.    
  17.     my $first_day = new DateTime(year => $year, month => $month, day => 1);
  18.     my $last_day = last_day_of_month DateTime(year => $year, month => $month);
  19.     my $wd = $first_day->day_of_week - 1;
  20.    
  21.     print $month . ". " . $monthes[$month - 1] . "\n";
  22.     print "$_\t" for qw /Пн Вт Ср Чт Пт Сб Вс/;
  23.     print "\n", "-" x 56, "\n";
  24.     print "\t" x $wd;
  25.    
  26.     for my $day (1 .. $last_day->day) {
  27.         my $number = $month == 1 ? roman($day) : cnv($day, $month);
  28.         print $number, "\t";
  29.        
  30.         $wd++;
  31.         if ($wd > 6) {
  32.             $wd = 0;
  33.             print "\n";
  34.         }
  35.     }
  36.    
  37.     print "\n" if $wd;
  38.     print "\n";
  39. }
  40.  
  41. sub cnv {
  42.     use integer;
  43.     my ($number, $base) = @_;
  44.    
  45.     my @alphabet = (0 .. 9, 'A' .. 'F');
  46.     my @result = ();
  47.    
  48.     while ($number) {
  49.         unshift @result, $alphabet[$number % $base];
  50.         $number /= $base;
  51.     }
  52.    
  53.     return join "", @result;
  54. }
  55.  
  56. sub roman {
  57.     my ($number) = @_;
  58.    
  59.     return {qw/
  60.         1 I 2 II 3 III 4 IV 5 V 6 VI 7 VII 8 VIII 9 IX 10 X
  61.         11 XI 12 XII 13 XIII 14 XIV 15 XV 16 XVI 17 XVII 18 XVIII 19 XIX 20 XX
  62.         21 XXI 22 XXII 23 XXIII 24 XXIV 25 XXV 26 XXVI 27 XXVII 28 XXVIII 29 XXIX 30 XXX
  63.         31 XXXI
  64.     /}->{$number};
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement