-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseq.pl
More file actions
70 lines (63 loc) · 1.34 KB
/
seq.pl
File metadata and controls
70 lines (63 loc) · 1.34 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl -w
use Getopt::Std;
#getopts('s:h');
my %opt;
getopts( 'hs:', \%opt );
$incremental = 1;
usage() if exists $opt{h};
if ($opt{s})
{
$separator = $opt{s};
}
else
{
$separator = "\n";
}
if ($#ARGV > 2)
{
print "$0: Extra operand \`$ARGV[-1]\' \n";
print "Try $0 -h\n";
exit 1;
}
if ($#ARGV == 2)
{
$incremental = $ARGV[1];
}
if ($#ARGV >= 1)
{
$runner = $ARGV[0];
}
if ($#ARGV == 0)
{
$runner = 1;
}
for($i=0; $i <= $#ARGV; $i++)
{
if($ARGV[$i] ne $ARGV[$i] + 0)
{
print "Try $0 -h\n";
exit 1;
}
}
if ($#ARGV >= 0)
{
$last = $ARGV[-1];
while($runner <= $last)
{
print $runner;# . $separator;
$runner += $incremental;
if ($runner <= $last)
{
print $separator;
}
}
print "\n";
}
sub usage
{
print "\t\tUsage: seq [OPTION]... LAST\n";
print "\t\tor: seq [OPTION]... FIRST LAST\n";
print "\t\tor: seq [OPTION]... FIRST INCREMENT LAST\n";
print "\t\tPrint numbers from FIRST to LAST, in steps of INCREMENT.\n";
print "\t\t-s \tuse STRING to separate numbers (default: \\n)\n";
}