From 60fcb8183e758e74f7b04480859df34183c2eee3 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 29 Jul 2019 17:26:59 +0100 Subject: Word wrapping --- challenge-019/simon-proctor/perl6/ch-2.p6 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 challenge-019/simon-proctor/perl6/ch-2.p6 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..e0bb089dde --- /dev/null +++ b/challenge-019/simon-proctor/perl6/ch-2.p6 @@ -0,0 +1,27 @@ +#!/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 } -- cgit From e398e78726ae1989afd57a882f56692a71de2e66 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 29 Jul 2019 17:28:06 +0100 Subject: Removed extra lines --- challenge-019/simon-proctor/perl6/ch-2.p6 | 2 -- 1 file changed, 2 deletions(-) diff --git a/challenge-019/simon-proctor/perl6/ch-2.p6 b/challenge-019/simon-proctor/perl6/ch-2.p6 index e0bb089dde..1af8bb16f6 100644 --- a/challenge-019/simon-proctor/perl6/ch-2.p6 +++ b/challenge-019/simon-proctor/perl6/ch-2.p6 @@ -2,8 +2,6 @@ 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) -- cgit