aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Proctor <simon.proctor@zoopla.co.uk>2021-02-01 13:16:50 +0000
committerSimon Proctor <simon.proctor@zoopla.co.uk>2021-02-01 13:16:50 +0000
commit60d0ec8c7160cd8b06163b8ea50c59b1df50ce35 (patch)
tree73a061cf5d63f97e080e3da8fa8dfa0521ea2cb8
parent9d5b485fe19209fa05b3a70a607ecc589387a86e (diff)
downloadperlweeklychallenge-club-60d0ec8c7160cd8b06163b8ea50c59b1df50ce35.tar.gz
perlweeklychallenge-club-60d0ec8c7160cd8b06163b8ea50c59b1df50ce35.tar.bz2
perlweeklychallenge-club-60d0ec8c7160cd8b06163b8ea50c59b1df50ce35.zip
Added comments.
-rw-r--r--challenge-098/simon-proctor/raku/ch-1.raku9
1 files changed, 9 insertions, 0 deletions
diff --git a/challenge-098/simon-proctor/raku/ch-1.raku b/challenge-098/simon-proctor/raku/ch-1.raku
index 098a789083..6ae13767ff 100644
--- a/challenge-098/simon-proctor/raku/ch-1.raku
+++ b/challenge-098/simon-proctor/raku/ch-1.raku
@@ -22,8 +22,12 @@ say "Self referential code is fun right?";
# While we have a truthy input
while ( my $val = prompt( "How many characters should I print? " ) ) {
my $rval = $val.Int();
+ # If $rval couldn't be cast to an Int it's a Failure which is Boolean false
+ # If it was a number then we check it matches the value (to catch floating points).
if ( $rval && $rval ~~ $val ) {
+ # Allow for negative read back.
if ( $rval < 0 ) {
+ # If we would read back to beyond the start just reset it.
if ( $handle.tell() >= $rval.abs ) {
$handle.seek($rval, SeekFromCurrent );
} else {
@@ -31,7 +35,11 @@ while ( my $val = prompt( "How many characters should I print? " ) ) {
}
}
my $res = $handle.readchars($rval.abs);
+ # I thought about reading back displaying backwards but... not instead it
+ # pulls the pointer back and rereads
say $res;
+ # If we got back less code points than we asked for (note not bytes)
+ # we are done.
if $res.codes != $rval.abs {
say "That's all folks";
last;
@@ -41,4 +49,5 @@ while ( my $val = prompt( "How many characters should I print? " ) ) {
}
}
+# All over. Say goodbye.
say "Bye";