From 3fa86e7eb1946c9a51fc70c2a5585f8bf9e449bb Mon Sep 17 00:00:00 2001 From: Alexander Pankoff Date: Mon, 1 Feb 2021 17:33:34 +0100 Subject: add perl solution for wk-098 ch-1.pl --- challenge-098/alexander-pankoff/perl/ch-1.pl | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 challenge-098/alexander-pankoff/perl/ch-1.pl 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; +} -- cgit