<?xml version="1.0" encoding="windows-1252"?>
<node id="1003882" title="What is the purpose of '||=' in the example code for Spreadsheet::XLSX" created="2012-11-14 14:42:08" updated="2012-11-14 14:42:08">
<type id="115">
perlquestion</type>
<author id="913355">
vt220</author>
<data>
<field name="doctext">
&lt;p&gt;I tried a modified version of the example code given in [http://search.cpan.org/~dmow/Spreadsheet-XLSX-0.13-withoutworldwriteables/lib/Spreadsheet/XLSX.pm].  It works very well and now I am trying to understand it.&lt;/p&gt;
&lt;p&gt;I am not sure what these two lines are doing.&lt;/p&gt;
&lt;c&gt;
$sheet -&gt; {MaxRow} ||= $sheet -&gt; {MinRow};
$sheet -&gt; {MaxCol} ||= $sheet -&gt; {MinCol};
&lt;/c&gt;
&lt;p&gt;My guess is that if &lt;tt&gt;MaxRow&lt;/tt&gt; or &lt;tt&gt;MaxCol&lt;/tt&gt; are undefined then they are set to equal &lt;tt&gt;MinRow&lt;/tt&gt; or &lt;tt&gt;MinCol&lt;/tt&gt; respectfully.  If that is true then under what circumstances is MAX not defined?&lt;/p&gt;
&lt;p&gt;Also, I &lt;tt&gt;Data::Dumper::Simple&lt;/tt&gt;'d &lt;tt&gt;$excel&lt;/tt&gt; and it appears &lt;tt&gt;MinCol&lt;/tt&gt; and &lt;tt&gt;MaxCol&lt;/tt&gt; does not vary by row i.e., it is set once for each worksheet.  So why execute it on each row?  Or did I read the dump incorrectly?&lt;/p&gt;
&lt;p&gt;Following is the code I ran:&lt;/p&gt;
&lt;c&gt;
use strict;
use warnings;
use Data::Dumper::Simple;
use Spreadsheet::XLSX;
#   use Text::Iconv;
#   my $converter = Text::Iconv -&gt; new ("utf-8", "windows-1251");

# Text::Iconv is not really required.
# This can be any object with the convert method. Or nothing.

#   my $excel = Spreadsheet::XLSX -&gt; new ('test.xlsx', $converter);

my $excel  = Spreadsheet::XLSX -&gt; new ($ARGV[0]);

print Dumper($excel);

foreach my $sheet (@{$excel -&gt; {Worksheet}}) {

    printf("Sheet: %s\n", $sheet-&gt;{Name});

    $sheet -&gt; {MaxRow} ||= $sheet -&gt; {MinRow};

    foreach my $row ($sheet -&gt; {MinRow} .. $sheet -&gt; {MaxRow}) {

        $sheet -&gt; {MaxCol} ||= $sheet -&gt; {MinCol};

        foreach my $col ($sheet -&gt; {MinCol} ..  $sheet -&gt; {MaxCol}) {

            my $cell = $sheet -&gt; {Cells} [$row] [$col];

            if ($cell) {
                printf("( %s , %s ) =&gt; %s\n", $row, $col, $cell -&gt; {Val});
            }
        }
    }
}
&lt;/c&gt;

&lt;p&gt;Thanks in advance!&lt;/p&gt;
</field>
</data>
</node>
