From 8a284d23235223f4a6462690371059b0653252c8 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Sun, 4 Aug 2019 21:12:50 +0100 Subject: - Added solution by Mark Anderson. --- challenge-019/mark-anderson/perl5/ch-2.pl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 challenge-019/mark-anderson/perl5/ch-2.pl diff --git a/challenge-019/mark-anderson/perl5/ch-2.pl b/challenge-019/mark-anderson/perl5/ch-2.pl new file mode 100644 index 0000000000..4fdb6a87ff --- /dev/null +++ b/challenge-019/mark-anderson/perl5/ch-2.pl @@ -0,0 +1,22 @@ +#!/usr/bin/env perl + +use Modern::Perl '2018'; + +my $line_break = $/; +my $space_width = 1; +my $line_width = 72; +my @text = split /\s+/, join '', <>; +my $space_left = $line_width; + +foreach my $word (@text) { + if((length $word) + $space_width > $space_left) { + $word = $line_break . $word; + $space_left = $line_width - (length $word); + } + + else { + $space_left -= (length $word) + $space_width; + } +} + +say "@text"; -- cgit