Proposed cleanup for the dirt mentioned in ExcelPerl.pm/getNextRow:

my $rowData = $sheet->Range("A$row:IV$row")->{Value}; # dirty

Idea: A range has a method address to stringify itself, giving the string one needs in the constructor à la range("A1:X1").

  1. Expand open by not only saving the lastRow, but also the maxCol:
    my $bottomRight = (split (/:/, $self->worksheet->UsedRange->addres +s(0,0)))[-1]; my ($colNameMax, $rowNumMax) = $bottomRight =~ /^([A-Z]+)(\d+)/; $self->lastRow( $rowNumMax ); $self->maxCol( $colNameMax );
    Also add maxCol to @ObjInterfaceMethod to initially create it.
  2. Now you can do the following in getNextRow:
    my $rowData = $sheet->Range("A$row:" . $self->maxCol . $row)->{Value};
    But we also have to change the construction of the list to iterate over in the foreach following:
    foreach my $value (ref $rowData ? reverse @{ $rowData->[0] } : $rowDat +a) {
    because $rowdata is only a scalar when maxCol eq 'A'.

We can take an additional step (now in excelPerl.pl) and compile (eval) the $perCode only once:

my $fn = eval "sub { my \@F = \@_; no warnings 'uninitialized'; $perlCode }"; die $@ if $@;

Maybe we want the no warnings as shown in that tight scope, since our first change made it more likely that an index out of range for @F will be tried to access in the $perlCode.

The former eval part in the while - getNextRow changes to

$fn->(@F);

with that.


In reply to Re: excelPerl V0.08 by pKai
in thread excelPerl V0.08 by strat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.