diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-07-29 20:53:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-29 20:53:24 +0100 |
| commit | 6b5119565534366862e22e40c417e1e7f4e2d457 (patch) | |
| tree | 9b692ad462b40e68c2f2fcdf12feb9449f9f26e2 | |
| parent | 148cacf688e1c0e2d191362653c01db93cae56cb (diff) | |
| parent | 250fa8ca4a1d6e96863a5074be1376503452b7c6 (diff) | |
| download | perlweeklychallenge-club-6b5119565534366862e22e40c417e1e7f4e2d457.tar.gz perlweeklychallenge-club-6b5119565534366862e22e40c417e1e7f4e2d457.tar.bz2 perlweeklychallenge-club-6b5119565534366862e22e40c417e1e7f4e2d457.zip | |
Merge pull request #6519 from oWnOIzRi/week175
add solution week 175 task 1
| -rw-r--r-- | challenge-175/steven-wilson/perl/ch-01.pl | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-175/steven-wilson/perl/ch-01.pl b/challenge-175/steven-wilson/perl/ch-01.pl new file mode 100644 index 0000000000..15a456dcbe --- /dev/null +++ b/challenge-175/steven-wilson/perl/ch-01.pl @@ -0,0 +1,25 @@ +#!/usr/bin/env perl +# Week 175 Task 1 +# Write a script to list Last Sunday of every month in the given year. + +use strict; +use warnings; +use DateTime; + +my $year = $ARGV[0]; +my $dt = DateTime->new( year => $year, month => 1, day => 1 ); +my %sundays; + +while ( $year == $dt->year ) { + if ( $dt->dow == 7 ) { + $sundays{ $dt->mon } = $dt->day; + $dt->add( days => 7 ); + } + else { + $dt->add( days => 1 ); + } +} + +for my $month ( sort { $a <=> $b } keys %sundays ) { + printf( "$year-%02d-$sundays{$month}\n", $month ); +} |
