Subject: | Warning 'Use of uninitialized' issued when empty lines in multi-line cells occure |
Hi,
While using Spreadsheet::ReadSXC-0.20 with perl 5.24.0 on Mac OS X 10.11.6 to parse .ods spreadsheet I got multiple warnings: Use of uninitialized value in join or string at /usr/local/Cellar/perl/5.24.0_1/lib/perl5/site_perl/5.24.0/Spreadsheet/ReadSXC.pm line 198.
The root cause were cells which contained multiple lines of text with some lines empty, for example when cell A1 contains 3 lines:
"First line
Third line"
then one warning will be issued.
The root cause are 'undef' values in @cell array for each empty line in multi-line cell. Proposed fix is to convert 'undef' values to empty strings "" prior processing:
--- Spreadsheet/ReadSXC.pm.orig 2016-08-23 18:35:07.000000000 +0200
+++ Spreadsheet/ReadSXC.pm 2016-08-23 18:40:18.000000000 +0200
@@ -195,7 +195,10 @@
}
# join cell contents and assign to current workbook cell
else {
- $workbook{$table}[$row][$col] = @cell ? join $options{ReplaceNewlineWith} || "", @cell : undef;
+ $workbook{$table}[$row][$col] = @cell ? join $options{ReplaceNewlineWith} || "",
+ map { defined $_ ? $_ : "" } @cell
+ :
+ undef;
}
# repeat current cell, if necessary
for (2..$repeat_cells) {