Commit 2c20e8ca authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

csv2json: some input validation

parent 3d845879
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -18,6 +18,21 @@ shift @csv_lines;
for my $line (@csv_lines) {
	if ( $csv->parse($line) ) {
		my ( $name, $ds100, $uic, $lat, $lon ) = $csv->fields;

		if ( not $name ) {
			say "Station name is mandatory -- skipping this line: $line";
			next;
		}
		if ( not $ds100 ) {
			say "DS100 is mandatory at the moment -- skipping this line: $line";
			next;
		}
		if ( not $uic or $uic !~ m{ ^ \d+ $ }x ) {
			say
"UIC is mandatory and must be numeric -- skipping this line: $line";
			next;
		}

		my $station = {
			name    => $name,
			ds100   => $ds100,