in reply to Text::xSV question - could this be written better?
The trick for setting nulls to "" might be too cute though. It relies on the way that Perl uses aliasing in a way that might puzzle whoever maintains the code. You might therefore prefer the more verbose:#$csvIn is a Text::xSV object. while ($csvIn->get_row()) { my %fields = $csvIn->extract_hash(); # time passes # set nulls to empty string. Have to do this or there will # be problems later printing the data rows. defined($_) or $_ = "" for values %fields; }
for (keys %fields) { unless (defined($fields{$_})) { $fields{$_} = ""; } }
|
|---|