diff options
| author | Simon Proctor <simon.proctor@zpg.co.uk> | 2019-07-29 17:26:59 +0100 |
|---|---|---|
| committer | Simon Proctor <simon.proctor@zpg.co.uk> | 2019-07-29 17:26:59 +0100 |
| commit | 60fcb8183e758e74f7b04480859df34183c2eee3 (patch) | |
| tree | 3a0132d1c7364f11badf96e32e09135903fd10b5 | |
| parent | 5890fbc9ce9a9832ec5e55f1c6bd8e871d017991 (diff) | |
| download | perlweeklychallenge-club-60fcb8183e758e74f7b04480859df34183c2eee3.tar.gz perlweeklychallenge-club-60fcb8183e758e74f7b04480859df34183c2eee3.tar.bz2 perlweeklychallenge-club-60fcb8183e758e74f7b04480859df34183c2eee3.zip | |
Word wrapping
| -rw-r--r-- | challenge-019/simon-proctor/perl6/ch-2.p6 | 27 |
1 files changed, 27 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..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 } |
