$csv->column_names($csv->fields);
- my $skipped = 0;
+ my %seen;
while (my $phash = $csv->getline_hr($fh)) {
- if (!$phash->{student_id}) { $skipped++; next; }
+ next unless $phash->{student_id};
- # Remove any non-alphanumeric characters.
+ # Remove all non-alphanumeric characters.
$phash->{student_id} =~ s/[^\w]//oag;
+ next unless $phash->{student_id};
+
# If the ID value is less than 4 characters, pad the value
# with zeros to be 4 characters long. This will effect
# the barcode and password. Only do this for teacher accounts.
if $is_teacher && length($phash->{student_id}) < 4;
# All teacher ID's, which can be alpha-numeric, are upper case.
+ # Student ID's can also be alpha-numeric, but remain in the
+ # provided case.
$phash->{student_id} = uc($phash->{student_id}) if $is_teacher;
- # Teacher cards have an extra 't' between district code and ID.
- $phash->{barcode} = $district_code .
- ($is_teacher ? 't' : '') . $phash->{student_id};
+ # Avoid processing duplicates
+ next if $seen{$phash->{student_id}};
+ $seen{$phash->{student_id}} = 1;
+
+ $phash->{barcode} = $district_code;
+ $phash->{barcode} .= 't' if $is_teacher;
+ $phash->{barcode} .= $phash->{student_id};
$row_handler->($phash);
}
}
$fh->close;
-
- announce('WARNING', "$skipped entries had no student_id") if $skipped;
}
# Determine which patrons in the file are new by testing whether their
iterate_csv_rows($row_handler);
- announce('INFO', "File contains ".scalar(@all_barcodes)." total students");
+ announce('INFO', "File contains ".scalar(@all_barcodes)." unique students");
my $all_barcodes = join(',', @all_barcodes);