-
Notifications
You must be signed in to change notification settings - Fork 1
/
numrowscols.pl
executable file
·74 lines (59 loc) · 1.77 KB
/
numrowscols.pl
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
71
72
73
74
#!/usr/bin/perl
#USAGE: numrowscols.pl file
#Outputs the number of consecutive rows with the same number of columns
use CommandLineInterface;
setScriptInfo(VERSION => '2.0',
CREATED => '2/5/2014',
AUTHOR => 'Robert William Leach',
CONTACT => '[email protected]',
COMPANY => 'Princeton University',
LICENSE => 'Copyright 2018',
HELP => ('This script tells you how many consecutive rows ' .
'have the same number of columns.'));
setDefaults(HEADER => 0,
ERRLIMIT => 3,
COLLISIONMODE => 'error', #,merge,rename (when outfile conflict)
DEFRUNMODE => 'usage',
DEFSDIR => undef);
my $iid = addInfileOption(GETOPTKEY => 'i|infile=s',
REQUIRED => 1,
PRIMARY => 1,
FLAGLESS => 1,
SMRY_DESC => 'Tab delimited text file.',
FORMAT_DESC => 'Tab delimited input text file.');
my $ttid = addOutfileTagteamOption(GETOPTKEY_SUFF => 'o|outfile-suffix=s',
GETOPTKEY_FILE => 'outfile=s',
FILETYPEID => $iid,
PRIMARY => 1,
DETAIL_DESC_SUFF => ('Extension appended ' .
'to file submitted ' .
'via -i.'),
DETAIL_DESC_FILE => 'Outfile.');
while(nextFileCombo())
{
my $file = getInfile($iid);
my $ofile = getOutfile($ttid);
openIn(*FILE,$file) || next;
openOut(*OUT,$ofile) || next;
print("$file\n#Rows\tCols\n");
$cnt = 0;
$num = 0;
$pnum = 0;
while(getLine(*FILE))
{
$num = scalar(split(/\t/,$_,-1));
if($pnum > 0 && $num == $pnum)
{$cnt++}
elsif($pnum == 0)
{$cnt=1}
else
{
print("$cnt\t$pnum\n");
$cnt=1;
}
$pnum=$num
}
print("$cnt\t$pnum\n");
closeIn(*FILE);
closeOut(*OUT);
}