in reply to CSV Files With Missing Values
If you are sure, you can do it 'your' way by amending your split to include the following map to can convert any empty strings to zeroes on the way through.
The contents of the map is a simple ternary which tests each value for an empty string, replaces it with zero if it matches, or else passes the value through unmolested otherwise.my ($server, @data) = map { $_ eq '' ? 0 : $_; } split /,/;
If your source data might contain trailing empty fields, and you don't want split to silently ignore them, you might also want to give split a limit of -1, like so:
my ($server, @data) = map { $_ eq '' ? 0 : $_ } split /,/, $_, -1;
|
|---|