aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-08-03 21:09:53 +0100
committerGitHub <noreply@github.com>2020-08-03 21:09:53 +0100
commit01ae634b3016a6a263b5318a37839ae938041586 (patch)
tree3707892ead45f44a25223bb71b9937768456c8ad
parent66c7c92b31b47e56ea4ac2e166795266df7aba27 (diff)
parent4a24622121e127e0d3fa75500ca5ceb5d8e7f71d (diff)
downloadperlweeklychallenge-club-01ae634b3016a6a263b5318a37839ae938041586.tar.gz
perlweeklychallenge-club-01ae634b3016a6a263b5318a37839ae938041586.tar.bz2
perlweeklychallenge-club-01ae634b3016a6a263b5318a37839ae938041586.zip
Merge pull request #2028 from fecundf/master
Solutions for #72, "Range"
-rw-r--r--challenge-072/yary-h/input.txt12
-rw-r--r--challenge-072/yary-h/range.pl14
-rw-r--r--challenge-072/yary-h/range.raku18
-rw-r--r--challenge-072/yary-h/range_ff.pl14
4 files changed, 58 insertions, 0 deletions
diff --git a/challenge-072/yary-h/input.txt b/challenge-072/yary-h/input.txt
new file mode 100644
index 0000000000..756958ea91
--- /dev/null
+++ b/challenge-072/yary-h/input.txt
@@ -0,0 +1,12 @@
+L1
+L2
+L3
+L4
+L5
+L6
+L7
+L8
+L9
+L10
+L11
+L12
diff --git a/challenge-072/yary-h/range.pl b/challenge-072/yary-h/range.pl
new file mode 100644
index 0000000000..204bd2255c
--- /dev/null
+++ b/challenge-072/yary-h/range.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+# Run as:
+# range.pl 4 10 < input.txt
+# or
+# range.pl 4 10 input.txt
+
+my ($begin_line, $end_line)=splice @ARGV,0,2;
+
+# Not using flip-flop .. want to simply exit on the end line
+while (<>) {
+ next if $. < $begin_line;
+ print;
+ exit if $. >=$end_line;
+}
diff --git a/challenge-072/yary-h/range.raku b/challenge-072/yary-h/range.raku
new file mode 100644
index 0000000000..b2caf65398
--- /dev/null
+++ b/challenge-072/yary-h/range.raku
@@ -0,0 +1,18 @@
+#!/usr/bin/env raku
+
+# Run as:
+# range.pl 4 10 < input.txt
+# or
+# range.pl 4 10 input.txt
+
+# Playing with command-line validation.
+# Lines are ints, end_line is greater than begin_line,
+# all input files are readable- OK to skip that, CatHandle would complain.
+sub MAIN(Int $line_to_start is copy, #= First line to print
+ Int $end_line where * >= $line_to_start, #= Last line to print
+ *@input_file where (*.all).IO.f #= File(s) to read from. Also reads STDIN.
+ ) {
+ .say if --$line_to_start < 1
+ for IO::CatHandle.new(@input_file, $*IN).lines($end_line)
+ # Alternative would be to use .lines.kv to get line num with line
+}
diff --git a/challenge-072/yary-h/range_ff.pl b/challenge-072/yary-h/range_ff.pl
new file mode 100644
index 0000000000..e7d83cec9d
--- /dev/null
+++ b/challenge-072/yary-h/range_ff.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl -n
+
+# Run as:
+# range.pl 4 10 < input.txt
+# or
+# range.pl 4 10 input.txt
+
+# This version abuses command-line option in shebang,
+# and also the flip-flop
+
+our ($begin_line, $end_line);
+BEGIN { ($begin_line, $end_line)=splice @ARGV,0,2 };
+
+$. == $begin_line .. print && $. >= $end_line && exit