aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE. Choroba <choroba@matfyz.cz>2019-08-04 00:06:33 +0200
committerE. Choroba <choroba@matfyz.cz>2019-08-04 00:22:12 +0200
commitc78d67d093595edab30a61e8d7b1e1c7c1dda672 (patch)
tree4d4187bc86c735b748cb5eaba6469e0d28fd6419
parent4c2c55fef51a2ddfed57a9b41fe9d94ef0f78c97 (diff)
downloadperlweeklychallenge-club-c78d67d093595edab30a61e8d7b1e1c7c1dda672.tar.gz
perlweeklychallenge-club-c78d67d093595edab30a61e8d7b1e1c7c1dda672.tar.bz2
perlweeklychallenge-club-c78d67d093595edab30a61e8d7b1e1c7c1dda672.zip
Improve E. Choroba's solution according to his blog post
-rw-r--r--challenge-019/e-choroba/blog.txt1
-rwxr-xr-xchallenge-019/e-choroba/perl5/ch-1.pl11
-rwxr-xr-xchallenge-019/e-choroba/perl5/ch-2.pl4
3 files changed, 8 insertions, 8 deletions
diff --git a/challenge-019/e-choroba/blog.txt b/challenge-019/e-choroba/blog.txt
new file mode 100644
index 0000000000..60e0749e67
--- /dev/null
+++ b/challenge-019/e-choroba/blog.txt
@@ -0,0 +1 @@
+http://blogs.perl.org/users/e_choroba/2019/08/perl-weekly-challenge-019-five-weekends-and-paragraph-wrapping.html
diff --git a/challenge-019/e-choroba/perl5/ch-1.pl b/challenge-019/e-choroba/perl5/ch-1.pl
index f6b0f73fa4..5b436e9287 100755
--- a/challenge-019/e-choroba/perl5/ch-1.pl
+++ b/challenge-019/e-choroba/perl5/ch-1.pl
@@ -10,9 +10,10 @@ my $date = 'Time::Piece'->strptime(
'1900-01-01 12:00:00', '%Y-%m-%d %H:%M:%S');
while ($date->year < 2020) {
- $date += ONE_DAY until $date->day eq 'Fri';
- if ($date->mday == 1 && $date->month_last_day == 31) {
- say $date->strftime('%Y-%m');
- }
- $date += ($date->month_last_day - $date->mday + 1) * ONE_DAY;
+ next if $date->day ne 'Fri';
+
+ say $date->strftime('%Y-%m') if $date->month_last_day == 31;
+
+} continue {
+ $date += $date->month_last_day * ONE_DAY;
}
diff --git a/challenge-019/e-choroba/perl5/ch-2.pl b/challenge-019/e-choroba/perl5/ch-2.pl
index d6705639d3..c1b1e9b76d 100755
--- a/challenge-019/e-choroba/perl5/ch-2.pl
+++ b/challenge-019/e-choroba/perl5/ch-2.pl
@@ -11,9 +11,7 @@ sub wrap_paragraph {
if (length $paragraph <= $width) {
$pos = length $paragraph;
} else {
- $pos = $width;
- --$pos until ' ' eq substr $paragraph, $pos, 1
- or $pos < 0;
+ $pos = rindex $paragraph, ' ', $width;
$pos = $width if $pos < 0;
}
$out .= substr $paragraph, 0, $pos, "";