Text processing/2: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 2,834: | Line 2,834: | ||
1993-03-28 |
1993-03-28 |
||
1995-03-26 |
1995-03-26 |
||
</pre> |
|||
=={{header|Snobol4}}== |
|||
Developed using the Snobol4 dialect Spitbol for Linux, version 4.0 |
|||
<lang Snobol4>* Read text/2 |
|||
v = array(24) |
|||
f = array(24) |
|||
tos = char(9) " " ;* break characters are both tab and space |
|||
pat1 = break(tos) . dstamp |
|||
pat2 = span(tos) break(tos) . *v[i] span(tos) (break(tos) | (len(1) rem)) . *f[i] |
|||
rowcount = 0 |
|||
hold_dstamp = "" |
|||
num_bad_rows = 0 |
|||
num_invalid_rows = 0 |
|||
in0 |
|||
row = input :f(endinput) |
|||
rowcount = rowcount + 1 |
|||
row ? pat1 = :f(invalid_row) |
|||
* duplicated datestamp? |
|||
* if dstamp = hold_dstamp then duplicated |
|||
hold_dstamp = differ(hold_dstamp,dstamp) dstamp :s(nodup) |
|||
output = dstamp ": datestamp at row " rowcount " duplicates datestamp at " rowcount - 1 |
|||
nodup |
|||
i = 1 |
|||
in1 |
|||
row ? pat2 = :f(invalid_row) |
|||
i = lt(i,24) i + 1 :s(in1) |
|||
* Is this a goodrow? |
|||
* if any flag is < 1 then row has bad data |
|||
c = 0 |
|||
goodrow |
|||
c = lt(c,24) c + 1 :f(goodrow2) |
|||
num_bad_rows = lt(f[c],1) num_bad_rows + 1 :s(goodrow2)f(goodrow) |
|||
goodrow2 |
|||
:(in0) |
|||
invalid_row |
|||
num_invalid_rows = num_invalid_rows + 1 |
|||
:(in0) |
|||
endinput |
|||
output = |
|||
output = "Total number of rows : " rowcount |
|||
output = "Total number of rows with invalid format: " num_invalid_rows |
|||
output = "Total number of rows with bad data : " num_bad_rows |
|||
output = "Total number of good rows : " rowcount - num_invalid_rows - num_bad_rows |
|||
end |
|||
</lang> |
|||
{{out}} |
|||
<pre>1990-03-25: datestamp at row 85 duplicates datestamp at 84 |
|||
1991-03-31: datestamp at row 456 duplicates datestamp at 455 |
|||
1992-03-29: datestamp at row 820 duplicates datestamp at 819 |
|||
1993-03-28: datestamp at row 1184 duplicates datestamp at 1183 |
|||
1995-03-26: datestamp at row 1911 duplicates datestamp at 1910 |
|||
Total number of rows : 5471 |
|||
Total number of rows with invalid format: 0 |
|||
Total number of rows with bad data : 454 |
|||
Total number of good rows : 5017 |
|||
</pre> |
</pre> |
||