aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-098/alexander-pankoff/perl/ch-1.pl33
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-098/alexander-pankoff/perl/ch-1.pl b/challenge-098/alexander-pankoff/perl/ch-1.pl
new file mode 100755
index 0000000000..19294205aa
--- /dev/null
+++ b/challenge-098/alexander-pankoff/perl/ch-1.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+use v5.20;
+use utf8;
+use strict;
+use warnings;
+use feature qw(say signatures);
+no warnings 'experimental::signatures';
+
+{
+ my ( $FILE, @numbers ) = @ARGV;
+ say readN( $FILE, $_ ) for @numbers;
+}
+
+sub readN ( $file, $chars ) {
+ state $filehandles = {};
+
+ my $fh;
+ if ( $filehandles->{$file} ) {
+ $fh = $filehandles->{$file};
+ }
+ else {
+ open( $fh, '<', $file );
+ $fh->binmode( ':utf8' );
+ $filehandles->{$file} = $fh;
+ }
+
+ my $out;
+ while ( $chars-- && !$fh->eof ) {
+ $out .= $fh->getc;
+ }
+
+ return $out;
+}