[Bangalore-pm] Need Help to optimise the code

Srinivas Reddy SReddy at securities.com
Mon Jun 15 05:33:34 PDT 2009


Hi ,

Please help to optimize the code below.  We basically read 2 xls files into an array @xls2 and @xls1 . For each cell we want to compare ( starting from col 32 ) values in each cell and if they are not equal we need to store it in a different array. This we will then use to bold those particular cells.

The loop which does this comparison could be replacement by some in built array difference kind of function. I am new to perl so apologies if I ve used any wrong terminologies here.  Appreciate your help on the same. Please find attached whole code as well for reference

sub cell_handler2 {

        my $workbook    = $_[0];
        my $sheet_index = $_[1];
        my $row         = $_[2];
        my $col         = $_[3];
        my $cell        = $_[4];
             # Construct array for Dx code

        push @xls2 , {
                        'row2' => $row,
                        'col2' => $col,
                        'value2' => $cell->value(),
        };
        return @xls2;

}
#print Dumper(@xls2);
# Print the End Time to read second excel file
print scalar(localtime) . ": End Reading Excel2 \n";

print scalar(localtime) . ": Start Populating Bolding Array \n";
# Inefficient way of looping
# Please change this as it could boost the performance significantly
for(@xls2) {
            if($_->{'col2'} > 32 && $_->{'row2'} > '0' ) {
                                    $newvalue = $_->{'value2'};
                                    $newrow = $_->{'row2'};
                                    $newcol = $_->{'col2'};
                                    for(@xls1) {
                                                $oldrow = $_->{'row1'};
                                                $oldcol = $_->{'col1'};
                                                if($_->{'col1'} > 32 && $_->{'row1'} > 0 && $_->{'row1'} eq $newrow && $_->{'col1'} eq $newcol) {
                                                                        $oldvalue = $_->{'value1'};
                                                                        last;
                                                }
                                    }
                                    if($oldvalue ne $newvalue) {
                                                push @bold_array , {
                                                            'row' => $_->{'row2'},
                                                            'col' => $_->{'col2'},
                                                            'value' => $_->{'value2'},
                                                };
                                    }
            }
}


Regards,

Srinivas Reddy

______________________________________________________________________
This communication contains information which is confidential. It is for the
exclusive use of the intended recipient(s). If you are not the intended
recipient(s) please note any distribution, copying or use of this
communication or the information in it is strictly prohibited. If you have
received this communication in error please notify us by e-mail or
by telephone (as above) and then delete the e-mail and all attachments and
any copies thereof.
______________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/bangalore-pm/attachments/20090615/99f2ccaf/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bold-unoptimized.pl
Type: application/octet-stream
Size: 5544 bytes
Desc: bold-unoptimized.pl
URL: <http://mail.pm.org/pipermail/bangalore-pm/attachments/20090615/99f2ccaf/attachment-0001.obj>


More information about the Bangalore-pm mailing list