ak47suk1

kalendar by johnburn

Nov 25th, 2011
136
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2. use integer;
  3.  
  4. %nama_bulan = (
  5. "jan" => 1,  "feb" => 2,  "mar" => 3,  "apr" => 4,
  6. "may" => 5,  "jun" => 6,  "jul" => 7,  "aug" => 8,
  7. "sep" => 9,  "oct" => 10, "nov" => 11, "dec" => 12,
  8. );
  9. @bulan = ("",
  10.   " Januari", " Februari",   "  Mac",   "  April",
  11.     "   May",    "  Jun",    "  Julai",  "  Ogos",
  12. "September",  " Oktober", " November", " Disember"
  13. );
  14. @max_hari = (0,31,28,31,30,31,30,31,31,30,31,30,31);
  15.  
  16. print "Sila masukkan bulan: ";
  17. $bulan_input = <>;
  18. if ($bulan_input =~ /^ *\d{1,2} *$/) {
  19.   die "Bulan mesti diantara 1 dan 12!\n" unless ($bulan_input>=1 && $bulan_input<=12);
  20. } else {
  21.   $bulan_input = $nama_bulan{lc(substr($bulan_input,0,3))};
  22.   die "Nama bulan tidak tepat: $ARGV[0]!\n" unless defined($bulan_input);
  23. }
  24. print "Sila masukkan tahun: ";
  25. $tahun = <>;
  26. die "Tahun tidak tepat: $tahun!\n" unless $tahun =~ /^ *\d{4} *$/;
  27. $tahun = int($tahun);
  28. die "Tahun mesti lebih besar dari 0!\n" unless $tahun>0;
  29. print "\n\t$bulan[$bulan_input] $tahun\n\nSun  Mon  Tue  Wed  Thu  Fri  Sat\n";
  30. $max_hari[2] = 29 if ($tahun%400==0) || (($tahun%4==0) && ($tahun%100!=0));
  31. --$tahun;
  32. $st = 1 + $tahun*365 + $tahun/4 - $tahun/100 + $tahun/400;
  33. for ($i=1; $i<$bulan_input; ++$i) {
  34.   $st += $max_hari[$i];
  35. }
  36. $st %= 7;
  37. for ($i=0; $i<$st; ++$i) {
  38.   print "     ";
  39. }
  40. for ($i=1; $i<=$max_hari[$bulan_input]; ++$i) {
  41.   printf "%3d  ", $i;
  42.   print "\n" if ($st+$i)%7==0;
  43. }
  44. print "\n\n";
  45.  
RAW Paste Data