[Bangalore-pm] Need Help to optimise the code

Kiran Kumar mkirank at gmail.com
Mon Jun 15 09:13:27 PDT 2009


Hi Srinivas,
     You will need to profile your code (check Devel::NYTProf  on CPAN) to
find out the exact bottleneck,

you can do a grep from xls1 once instead of going through all the values
each time

my @xls1_vals = grep {$_->{'row2'} > 32 && $_->{'col2'} > 0} @xls1;

for my $row ( grep {$_->{'row2'} > 32 && $_->{'col2'} > 0} @xls2 )
{

}


Its easier to actually find out where the issue is first


-Kiran


2009/6/15 Srinivas Reddy <SReddy at securities.com>

>  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.
> ______________________________________________________________________
>
> _______________________________________________
> Bangalore-pm mailing list
> Bangalore-pm at pm.org
> http://mail.pm.org/mailman/listinfo/bangalore-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/bangalore-pm/attachments/20090615/3c824592/attachment.html>


More information about the Bangalore-pm mailing list