aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-07-29 17:42:46 +0100
committerGitHub <noreply@github.com>2019-07-29 17:42:46 +0100
commit6330daa8b0c4f092fb0d358a9560054924b9499a (patch)
treec94c04ebaa06d5f08a903ce511dd461c30bf66bf
parentd868660e9770a750721ea3379ffe860759e70c43 (diff)
parente398e78726ae1989afd57a882f56692a71de2e66 (diff)
downloadperlweeklychallenge-club-6330daa8b0c4f092fb0d358a9560054924b9499a.tar.gz
perlweeklychallenge-club-6330daa8b0c4f092fb0d358a9560054924b9499a.tar.bz2
perlweeklychallenge-club-6330daa8b0c4f092fb0d358a9560054924b9499a.zip
Merge pull request #445 from Scimon/master
Done part 2.
-rw-r--r--challenge-019/simon-proctor/perl6/ch-2.p625
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-019/simon-proctor/perl6/ch-2.p6 b/challenge-019/simon-proctor/perl6/ch-2.p6
new file mode 100644
index 0000000000..1af8bb16f6
--- /dev/null
+++ b/challenge-019/simon-proctor/perl6/ch-2.p6
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+#| Read from STDIN and wrap to the given number of characters
+multi sub MAIN (
+ UInt() $width = 80, #= Width to wrap to (default 80 characters)
+) {
+ my $out = "";
+ my $left = $width;
+ for $*IN.words -> $word {
+ if $word.codes + 1 > $left {
+ say $out;
+ $out = "";
+ $left = $width;
+ }
+ $out = $out ?? "$out $word" !! $word;
+ $left = $width - $out.codes;
+ }
+ say $out if $out;
+}
+
+
+#| Display help
+multi sub MAIN( Bool :h(:$help) where ?* ) { say $*USAGE }