diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-08-04 21:12:50 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-08-04 21:12:50 +0100 |
| commit | 8a284d23235223f4a6462690371059b0653252c8 (patch) | |
| tree | d5eb8c1a66f45dac02eed0cbbb735574448473a2 | |
| parent | 3355ce1d0967c2d8b9b637458e45a91235544040 (diff) | |
| download | perlweeklychallenge-club-8a284d23235223f4a6462690371059b0653252c8.tar.gz perlweeklychallenge-club-8a284d23235223f4a6462690371059b0653252c8.tar.bz2 perlweeklychallenge-club-8a284d23235223f4a6462690371059b0653252c8.zip | |
- Added solution by Mark Anderson.
| -rw-r--r-- | challenge-019/mark-anderson/perl5/ch-2.pl | 22 |
1 files changed, 22 insertions, 0 deletions
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"; |
