diff options
| author | Simon Proctor <simon.proctor@zoopla.co.uk> | 2021-02-01 13:09:30 +0000 |
|---|---|---|
| committer | Simon Proctor <simon.proctor@zoopla.co.uk> | 2021-02-01 13:09:30 +0000 |
| commit | d9b6efeea7a9664ac3d651fa651f772087ca6e9f (patch) | |
| tree | 4732a8be6788b5ba107f8624674582904f52d7df | |
| parent | 87f34df3cbddc3c530c7984f31b2d442ffe2f184 (diff) | |
| download | perlweeklychallenge-club-d9b6efeea7a9664ac3d651fa651f772087ca6e9f.tar.gz perlweeklychallenge-club-d9b6efeea7a9664ac3d651fa651f772087ca6e9f.tar.bz2 perlweeklychallenge-club-d9b6efeea7a9664ac3d651fa651f772087ca6e9f.zip | |
Self reading script that demonstrates file pointer positioning in Raku
| -rw-r--r-- | challenge-098/simon-proctor/raku/ch-1.raku | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/challenge-098/simon-proctor/raku/ch-1.raku b/challenge-098/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..e015d35687 --- /dev/null +++ b/challenge-098/simon-proctor/raku/ch-1.raku @@ -0,0 +1,44 @@ +#!/usr/bin/env raku + +# Switch the langauge version to general v6. +# This generally helps in case you run a Raku script with Perl +use v6; + +# This whole script is the main sub. +unit sub MAIN(); + +# This script will read and print out itself by the number of characters +# that you tell it to until it's stopped or runs out of text. + +# Note that characters include Uncide ones like £€æßðđŋŧ¶«»¢“”ŋŧ←ħ +# This is cool. + +# Get out filehandle +my $handle = $?FILE.IO.open( :r ); + +# Give some opening sprawl +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 ~~ $val ) { + if ( $rval < 0 ) { + if ( $handle.tell() >= $rval.abs ) { + $handle.seek($rval, SeekFromCurrent ); + } else { + $handle.seek(0, SeekFromBeginning ); + } + } + my $res = $handle.readchars($rval.abs); + say $res; + if $res.codes != $rval.abs { + say "That's all folks"; + last; + } + } else { + say "Please enter an integer. Thanks."; + } +} + +say "Bye"; |
