in reply to Auto-filling an array
Note that commented-out line: that works just as well. I haven't benchmarked it, so I don't know which is faster, but other maintainers were griping about the map{}, so I replaced it.$line = $csv->getline($io); # .. some error-handling stuff. for (@$line) { $_ = '<NULL>' unless defined } #~ @$line = map { defined $_ ? $_ : '<NULL>' } @$line
The basic logic (in both cases) is that I look for undefined values (you could also look for the empty string by substituting $_ eq '' for defined $_) and replace them with something.
This is, in general, better than prefilling: you need not alter this code if the length of your lines change.
Anima Legato
.oO all things connect through the motion of the mind
|
|---|