aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 }