aboutsummaryrefslogtreecommitdiff
path: root/challenge-072/duncan-c-white/perl/ch-2.pl
blob: 0a8f24618b771a6c472b1cf887c71741a8831384 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl
#
# Task 2: "Lines Range
# 
# You are given a text file name $file and range $A - $B where $A <= $B.
# 
# Write a script to display lines range $A and $B in the given file.
#
# Example
# Input:
#    $ cat input.txt
#    L1
#    L2
#    L3
#    L4
#    ...
#    ...
#    L100
#
# $A = 4 and $B = 12
#
# Output:
#
#    L4
#    L5
#    L6
#    ...
#    L10
#    L11
#    L12
# "
#
# My notes: ok.  Seems even easier.  I/O and a line number count (let's use $.)
#
 

use strict;
use warnings;
use feature 'say';
#use Function::Parameters;
#use Data::Dumper;

die "Usage: line-range FROM TO [filename]\n" unless @ARGV==2 || @ARGV==3;
my $from = shift;
my $to = shift;

die "line-range: 1 <= FROM <= TO ($from..$to given)\n"
	unless $from>=1 && $to>=$from;

while( <> )
{
	print if $. >= $from && $. <= $to;
}