foreach my $vn (sort { ksmap($a) cmp ksmap($b) } keys %o) {
my $val= $o{$vn};
- die if $val =~ m/\n|\r|\t/;
+ die if $val =~ m/\n|\r/;
$metadata .= "$vn\t$o{$vn}\n";
}
exec 'gunzip'; die $!;
}
-sub bad_data ($) { fail("bad data: line $.: $_[0]"); }
-
-our %done;
-
while (<GZ>) {
- !m/\P{IsPrint}/ or die bad_data('nonprinting char(s)');
- !m/\\/ or bad_data('data contains backslashes');
- my @v= split /\t/;
- @v==6 or bad_data('wrong number of fields');
- my ($commod,$stall) = @v;
- defined $commods{$commod} or bad_data("unknown commodity \`$commod'");
- $stall =~ m/^\p{IsUpper}|^[0-9]/ or bad_data("stall not capitalised");
- !exists $done{$commod,$stall} or bad_data("repeated data");
- $done{$commod,$stall}= 1;
- foreach my $i (2..5) {
- my $f= $v[$i];
- $f =~ m/^(|0|[1-9][0-9]{0,5}|\>1000)$/ or bad_data("bad field $i");
- ($i % 2) or ($f !~ m/\>/) or bad_data("> in field $i price");
- }
+ check_tsv_line($_,\&fail);
}
GZ->error and die $!;
$?=0; close GZ; $? and fail("gunzip for check failed code $?");