diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-12-02 18:03:00 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-02 18:03:00 +0000 |
| commit | 8482d1e2baa5587e29274366c960f2aaf09fb421 (patch) | |
| tree | 50ea9ee281f3bd34995e7206864e9f95d9ae5b4a | |
| parent | 2aa06cd3f8c50b6e86776066f7ea6c763d9acb2e (diff) | |
| parent | 664eeb412e1688bbf32d6e348df2c6ec8ae06086 (diff) | |
| download | perlweeklychallenge-club-8482d1e2baa5587e29274366c960f2aaf09fb421.tar.gz perlweeklychallenge-club-8482d1e2baa5587e29274366c960f2aaf09fb421.tar.bz2 perlweeklychallenge-club-8482d1e2baa5587e29274366c960f2aaf09fb421.zip | |
Merge pull request #996 from oWnOIzRi/week37
add solution for week 37 task 1
| -rw-r--r-- | challenge-037/steven-wilson/perl5/ch-1.pl | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-037/steven-wilson/perl5/ch-1.pl b/challenge-037/steven-wilson/perl5/ch-1.pl new file mode 100644 index 0000000000..6ab51ad060 --- /dev/null +++ b/challenge-037/steven-wilson/perl5/ch-1.pl @@ -0,0 +1,28 @@ +#!/usr/bin/env perl +# Author: Steven Wilson +# Date: 2019-12-02 +# Week: 037 +# Task #1 +# Write a script to calculate the total number of weekdays (Mon-Fri) in +# each month of the year 2019. + +use strict; +use warnings; +use feature qw/ say /; +use DateTime; + +my @months = qw/ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec /; +my $year = "2019"; +my %weekdays_in_month; +my $dt = DateTime->new( year => $year ); + +while ( $dt->year eq $year ) { + if ( $dt->dow() < 6 ) { + $weekdays_in_month{ $dt->month_abbr() }++; + } + $dt->add( days => 1 ); +} + +for my $month (@months) { + say "$month: $weekdays_in_month{$month}"; +} |
