Text processing/2: Difference between revisions

m
Added the Sidef language
m (→‎{{header|REXX}}: added/changed whitespace and comments, simplified the COMMAS subroutine.)
m (Added the Sidef language)
Line 2,538:
Invalid data records: 454
Total records: 5471
</pre>
 
=={{header|Sidef}}==
{{trans|Perl 6}}
<lang ruby>var good_records = 0;
var dates = Hash.new -> default(0);
 
ARGF.each { |line|
line ~~ /^(\d\d\d\d-\d\d-\d\d)((?:\h+\d+\.\d+\h+-?\d+){24})\s*$/;
dates[$1]++;
var i = 0;
$2.words.all{|n| i++ is_even || (n.to_num >= 1) } && good_records++;
}
 
say "#{good_records} good records out of #{$.} total";
say 'Repeated timestamps:';
say dates.pairs.grep{ .second > 1 }.map { .first }.sort.join("\n");</lang>
{{out}}
<pre>
$ sidef script.sf < readings.txt
5017 good records out of 5471 total
Repeated timestamps:
1990-03-25
1991-03-31
1992-03-29
1993-03-28
1995-03-26
</pre>
 
2,747

edits