in reply to excelPerl V0.08

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.

Replies are listed 'Best First'.
Re^2: excelPerl V0.08
by strat (Canon) on Jan 17, 2007 at 09:47 UTC

    @pKai: thank you for these good ideas; I added them in V0.09

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"