[Bangalore-pm] Need Help to optimise the code

simran simran at tlims.cc
Mon Jun 15 05:47:10 PDT 2009


Hi Srinivas,

The code is not very complex, and unless you change the structure, it will
not optimise too much... better to write it neatly (and with better arg
passing... as suggested in the email by Ravish.

If you are looking for absolute speed, better to write in in C and plug it
in via XS.

simran.

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


More information about the Bangalore-pm mailing list