-1

I have requirement to check if each row in a csv file has all columns defined as per header even if no value it should be like '||' where '|' is seperator. example:

EmpId|EmpName|EmpSalary|EmpDept -> Header

001|AAA|100|Dept1

002|BBB||Dept2 --> this row is valid even though Salary has no value

003|AAA|Dept1 ---> this row is invalid.

Since I am using CSV_XS (reading file into arrayOfHashes)for easier data manipulation, how do i check above scenario using CSV_XS where file has read into array of hashes. Thanks - Kumar

Kumar
  • 1

1 Answers1

0
my $header_row = $csv->getline($fh)
   or die("No header\n");

my $num_header_fields = @$header_row;

while (my $row = $csv->getline($fh)) {
    if (@$row != $num_header_fields) {
        # Invalid
        ...
    }

    ...
}
ikegami
  • 367,544
  • 15
  • 269
  • 518