[Bangalore-pm] Need Help to optimise the code

Kumar, Ravish ravish.kumar at gs.com
Mon Jun 15 05:44:02 PDT 2009


First thing :

my $workbook    = $_[0];

        my $sheet_index = $_[1];

        my $row         = $_[2];

        my $col         = $_[3];

        my $cell        = $_[4];

don't accept input parms like this, this degardes the performance and
code doesn't look nice.

 

above thing should be replaced  like this :

my ($workbook, $sheet_index, $row, $col, $cell ) = @_;

 

 

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'},

                                                };

                                    }

            }

}

 

Same thing as above, 

Iterate loop like :

 

Foreach my $value (@xls2) {

    $value->{'col2'} . ......

 

}

 

 

 

 

From: bangalore-pm-bounces+ravish.kumar=gs.com at pm.org
[mailto:bangalore-pm-bounces+ravish.kumar=gs.com at pm.org] On Behalf Of
Srinivas Reddy
Sent: Monday, June 15, 2009 6:04 PM
To: bangalore-pm at pm.org
Subject: [Bangalore-pm] Need Help to optimise the code

 

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/be4f49ff/attachment-0001.html>


More information about the Bangalore-pm mailing list