Subject: | Uninitialized $row, $col can be minimized by cautious default |
Date: | Mon, 14 Oct 2013 10:07:08 -0400 |
To: | <bug-Spreadsheet-XLSX [...] rt.cpan.org> |
From: | "Greg Owen" <gowen [...] swynwyr.com> |
In some cases, $row and $col are not being set for a worksheet. As a result,
when Spreadsheet::XLSX is parsing the worksheet, it spews warnings as follows
(over and over and over and...):
Use of uninitialized value $row in numeric lt (<) at
/usr/local/share/perl5/Spreadsheet/XLSX.pm line 194.
Use of uninitialized value $col in numeric lt (<) at
/usr/local/share/perl5/Spreadsheet/XLSX.pm line 195.
Use of uninitialized value $row in numeric gt (>) at
/usr/local/share/perl5/Spreadsheet/XLSX.pm line 196.
Use of uninitialized value in numeric gt (>) at
/usr/local/share/perl5/Spreadsheet/XLSX.pm line 196.
Use of uninitialized value $col in numeric gt (>) at
/usr/local/share/perl5/Spreadsheet/XLSX.pm line 197.
Use of uninitialized value in numeric gt (>) at
/usr/local/share/perl5/Spreadsheet/XLSX.pm line 197.
Use of uninitialized value $row in array element at
/usr/local/share/perl5/Spreadsheet/XLSX.pm line 214.
Use of uninitialized value $col in array element at
/usr/local/share/perl5/Spreadsheet/XLSX.pm line 214.
I have not yet determined why this worksheet can't be parsed - I suspect it's
because the worksheet has little to no native content and consists entirely of
formulas referencing data on another worksheet.
In any case, the error spew can be resolved by setting $row and $col to an
initial value of 0. It seems a proper bit of defensive programming to assume a
worksheet has dimensions 0x0 until proven otherwise by getting a correct
setting. If, as is the case that I'm experiencing, it never gets that proper
setting, at least it won't spew messages ad infinitum.
I propose the following change to minimize disruption by unfriendly worksheets:
% diff -c XLSX.pm.orig XLSX.pm
*** XLSX.pm.orig 2013-10-14 09:32:05.081273321 -0400
--- XLSX.pm 2013-10-14 10:02:20.118579289 -0400
***************
*** 149,155 ****
my $member_sheet = $self -> {zip} -> memberNamed
("xl/$sheet->{path}") or next;
! my ($row, $col);
my $flag = 0;
my $s = 0;
--- 149,156 ----
my $member_sheet = $self -> {zip} -> memberNamed
("xl/$sheet->{path}") or next;
! my $row = 0;
! my $col = 0;
my $flag = 0;
my $s = 0;