Text processing/2: Difference between revisions
Content added Content deleted
Line 1,918: | Line 1,918: | ||
1993-03-28 => [1183 1184] |
1993-03-28 => [1183 1184] |
||
1995-03-26 => [1910 1911]</pre> |
1995-03-26 => [1910 1911]</pre> |
||
=={{header|Phix}}== |
|||
<lang Phix>sequence lines = read_lines("demo\\rosetta\\readings.txt") |
|||
include builtins\timedate.e |
|||
integer all_good = 0 |
|||
string fmt = "%d-%d-%d\t"&join(repeat("%f",48),'\t') |
|||
sequence extset = sq_mul(tagset(24),2) -- {2,4,6,..48} |
|||
--The extract routine has been added as a builtin for 0.8.0+. If you don't yet have it, just use this: |
|||
--function extract(sequence source, indexes) |
|||
-- for i=1 to length(indexes) do |
|||
-- indexes[i] = source[indexes[i]] |
|||
-- end for |
|||
-- return indexes |
|||
--end function |
|||
for i=1 to length(lines) do |
|||
string li = lines[i] |
|||
sequence r = scanf(li,fmt), this, last |
|||
if length(r)!=1 then |
|||
printf(1,"bad line [%d]:%s\n",{i,li}) |
|||
else |
|||
this = r[1][1..3] |
|||
if i>1 and this=last then |
|||
printf(1,"duplicate line for %04d/%02d/%02d\n",last) |
|||
end if |
|||
last = this |
|||
all_good += sum(sq_le(extract(r[1][4..$],extset),0))=0 |
|||
end if |
|||
end for |
|||
printf(1,"Valid records %d of %d total\n",{all_good, length(lines)})</lang> |
|||
{{out}} |
|||
<pre> |
|||
duplicate line for 1990/03/25 |
|||
duplicate line for 1991/03/31 |
|||
duplicate line for 1992/03/29 |
|||
duplicate line for 1993/03/28 |
|||
duplicate line for 1995/03/26 |
|||
Valid records 5017 of 5471 total |
|||
</pre> |
|||
=={{header|PHP}}== |
=={{header|PHP}}== |