in reply to CSV Files With Missing Values
First of all, don't use split for parsing CSV files. It's bound to explode in your face. Search for CSV in the advanced search to see how many others already found out. Instead, use Text::CSV_XS or Text::CSV_PP for parsing the data
CSV data has by defenition no type, but with Text::CSV_XS, you can force it to have a type.
Your code should be something like:
use strict; use warnings; use IO::Handle; use Text::CSV_XS; open my $fh, "<", "data.csv" or die "data.csv: $!"; my $csv = Text::CSV_XS->new ({ binary => 1 }); while (my $row = $csv->getline ($fh)) { my ($server, @data) = @$row; $data[0] ||= 0; # ... more processing } close $fh;
|
|---|