Try using Array module <div><a href="http://search.cpan.org/~muenalan/Class-Maker-0.05.18/Maker/Examples/Array.pm">http://search.cpan.org/~muenalan/Class-Maker-0.05.18/Maker/Examples/Array.pm</a><br><br><div class="gmail_quote">
On Tue, Jun 16, 2009 at 3:01 AM, <span dir="ltr"><<a href="mailto:bangalore-pm-request@pm.org">bangalore-pm-request@pm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Send Bangalore-pm mailing list submissions to<br>
<a href="mailto:bangalore-pm@pm.org">bangalore-pm@pm.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
<a href="http://mail.pm.org/mailman/listinfo/bangalore-pm" target="_blank">http://mail.pm.org/mailman/listinfo/bangalore-pm</a><br>
or, via email, send a message with subject or body 'help' to<br>
<a href="mailto:bangalore-pm-request@pm.org">bangalore-pm-request@pm.org</a><br>
<br>
You can reach the person managing the list at<br>
<a href="mailto:bangalore-pm-owner@pm.org">bangalore-pm-owner@pm.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of Bangalore-pm digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
1. Re: Need Help to optimise the code (Kiran Kumar)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Mon, 15 Jun 2009 16:30:54 -0500<br>
From: Kiran Kumar <<a href="mailto:mkirank@gmail.com">mkirank@gmail.com</a>><br>
Subject: Re: [Bangalore-pm] Need Help to optimise the code<br>
To: Srinivas Reddy <<a href="mailto:SReddy@securities.com">SReddy@securities.com</a>><br>
Cc: "<a href="mailto:bangalore-pm@pm.org">bangalore-pm@pm.org</a>" <<a href="mailto:bangalore-pm@pm.org">bangalore-pm@pm.org</a>><br>
Message-ID:<br>
<<a href="mailto:b2d58a680906151430l1622dfaam9d711a6982cb1068@mail.gmail.com">b2d58a680906151430l1622dfaam9d711a6982cb1068@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="windows-1252"<br>
<br>
you will not be able to compare hashes but you can convert your data to<br>
strings and it will make it easier , something like this<br>
<br>
#!perl<br>
use strict;<br>
<br>
use warnings;<br>
use Data::Dumper;<br>
<br>
my @arr =(<br>
{<br>
'row' => 33,<br>
'col' => 1,<br>
'value' => 'xx',<br>
},<br>
<br>
{<br>
'row' => 30,<br>
'col' => 1,<br>
'value' => 'zz',<br>
},<br>
<br>
{<br>
'row' => 34,<br>
'col' => 1,<br>
'value' => 'yy',<br>
},<br>
<br>
);<br>
<br>
my @arr1 =(<br>
<br>
{<br>
'row' => 33,<br>
'col' => 1,<br>
'value' => 'xx',<br>
},<br>
<br>
{<br>
'row' => 30,<br>
'col' => 1,<br>
'value' => 'zz',<br>
},<br>
<br>
{<br>
'row' => 35,<br>
'col' => 1,<br>
'value' => 'yy',<br>
},<br>
<br>
);<br>
<br>
<br>
my @vals = map {$_->{'row'} > 32 && $_->{'col'} > 0 ?stringify(%$_):()}<br>
@arr;<br>
my @vals1 = map {$_->{'row'} > 32 && $_->{'col'} > 0 ?stringify(%$_):()}<br>
@arr1;<br>
<br>
<br>
my %hash;<br>
@hash{@vals} = 1 x @vals;<br>
my @diff = grep {not exists$hash{$_}} @vals1;<br>
<br>
<br>
sub stringify {<br>
return "@_";<br>
}<br>
<br>
<br>
<br>
<br>
2009/6/15 Srinivas Reddy <<a href="mailto:SReddy@securities.com">SReddy@securities.com</a>><br>
<br>
> Hi Thnx a lot for your quick help. Sry C is rules out as this willl form<br>
> a part of perl script and we have ?C? Expertise issue as well. I think<br>
> kumars solution would really help . Let us rewrite it and check the<br>
> performance.<br>
><br>
><br>
><br>
> I am still looking at a function which takes 2 arrays and gives me the<br>
> difference in them , in my case these array contain my xls file ( row , col<br>
> and value associated with each cell ) .<br>
><br>
><br>
><br>
> Regards,<br>
><br>
><br>
><br>
> Srinivas Reddy<br>
><br>
> Asia Technology and Global Projects Manager<br>
><br>
> Skype : sreddyisi<br>
><br>
> Cell : +91 9740076449<br>
><br>
> LandLine : +91 9900524073/74/76./78<br>
><br>
> Fax : +91 8026729764<br>
><br>
> Url : <a href="http://www.securities.com" target="_blank">www.securities.com</a><br>
><br>
> <a href="http://www.thefinancialnet.com" target="_blank">www.thefinancialnet.com</a><br>
><br>
> <a href="http://elearning.securities.com" target="_blank">elearning.securities.com</a><br>
><br>
> P Please consider the environment before printing this email<br>
> ------------------------------<br>
><br>
> *From:* <a href="mailto:simrangambhir@gmail.com">simrangambhir@gmail.com</a> [mailto:<a href="mailto:simrangambhir@gmail.com">simrangambhir@gmail.com</a>] *On<br>
> Behalf Of *simran<br>
> *Sent:* Monday, June 15, 2009 6:17 PM<br>
> *To:* Srinivas Reddy<br>
> *Cc:* <a href="mailto:bangalore-pm@pm.org">bangalore-pm@pm.org</a><br>
> *Subject:* Re: [Bangalore-pm] Need Help to optimise the code<br>
><br>
><br>
><br>
> Hi Srinivas,<br>
><br>
> The code is not very complex, and unless you change the structure, it will<br>
> not optimise too much... better to write it neatly (and with better arg<br>
> passing... as suggested in the email by Ravish.<br>
><br>
> If you are looking for absolute speed, better to write in in C and plug it<br>
> in via XS.<br>
><br>
> simran.<br>
><br>
> 2009/6/15 Srinivas Reddy <<a href="mailto:SReddy@securities.com">SReddy@securities.com</a>><br>
><br>
> Hi ,<br>
><br>
><br>
><br>
> Please help to optimize the code below. We basically read 2 xls files into<br>
> an array @xls2 and @xls1 . For each cell we want to compare ( starting from<br>
> col 32 ) values in each cell and if they are not equal we need to store it<br>
> in a different array. This we will then use to bold those particular cells.<br>
><br>
><br>
><br>
> The loop which does this comparison could be replacement by some in built<br>
> array difference kind of function. I am new to perl so apologies if I ve<br>
> used any wrong terminologies here. Appreciate your help on the same. Please<br>
> find attached whole code as well for reference<br>
><br>
><br>
><br>
> sub cell_handler2 {<br>
><br>
><br>
><br>
> my $workbook = $_[0];<br>
><br>
> my $sheet_index = $_[1];<br>
><br>
> my $row = $_[2];<br>
><br>
> my $col = $_[3];<br>
><br>
> my $cell = $_[4];<br>
><br>
> # Construct array for Dx code<br>
><br>
><br>
><br>
> push @xls2 , {<br>
><br>
> 'row2' => $row,<br>
><br>
> 'col2' => $col,<br>
><br>
> 'value2' => $cell->value(),<br>
><br>
> };<br>
><br>
> return @xls2;<br>
><br>
><br>
><br>
> }<br>
><br>
> #print Dumper(@xls2);<br>
><br>
> # Print the End Time to read second excel file<br>
><br>
> print scalar(localtime) . ": End Reading Excel2 \n";<br>
><br>
><br>
><br>
> print scalar(localtime) . ": Start Populating Bolding Array \n";<br>
><br>
> # Inefficient way of looping<br>
><br>
> # Please change this as it could boost the performance significantly<br>
><br>
> for(@xls2) {<br>
><br>
> if($_->{'col2'} > 32 && $_->{'row2'} > '0' ) {<br>
><br>
> $newvalue = $_->{'value2'};<br>
><br>
> $newrow = $_->{'row2'};<br>
><br>
> $newcol = $_->{'col2'};<br>
><br>
> for(@xls1) {<br>
><br>
> $oldrow = $_->{'row1'};<br>
><br>
> $oldcol = $_->{'col1'};<br>
><br>
> if($_->{'col1'} > 32 &&<br>
> $_->{'row1'} > 0 && $_->{'row1'} eq $newrow && $_->{'col1'} eq $newcol) {<br>
><br>
><br>
> $oldvalue = $_->{'value1'};<br>
><br>
><br>
> last;<br>
><br>
> }<br>
><br>
> }<br>
><br>
> if($oldvalue ne $newvalue) {<br>
><br>
> push @bold_array , {<br>
><br>
> 'row' =><br>
> $_->{'row2'},<br>
><br>
> 'col' =><br>
> $_->{'col2'},<br>
><br>
> 'value' =><br>
> $_->{'value2'},<br>
><br>
> };<br>
><br>
> }<br>
><br>
> }<br>
><br>
> }<br>
><br>
><br>
><br>
><br>
><br>
> Regards,<br>
><br>
><br>
><br>
> Srinivas Reddy<br>
><br>
><br>
> ______________________________________________________________________<br>
> This communication contains information which is confidential. It is for<br>
> the<br>
> exclusive use of the intended recipient(s). If you are not the intended<br>
> recipient(s) please note any distribution, copying or use of this<br>
> communication or the information in it is strictly prohibited. If you have<br>
> received this communication in error please notify us by e-mail or<br>
> by telephone (as above) and then delete the e-mail and all attachments and<br>
> any copies thereof.<br>
> ______________________________________________________________________<br>
><br>
><br>
> _______________________________________________<br>
> Bangalore-pm mailing list<br>
> <a href="mailto:Bangalore-pm@pm.org">Bangalore-pm@pm.org</a><br>
> <a href="http://mail.pm.org/mailman/listinfo/bangalore-pm" target="_blank">http://mail.pm.org/mailman/listinfo/bangalore-pm</a><br>
><br>
><br>
><br>
> ______________________________________________________________________<br>
> This communication contains information which is confidential. It is for<br>
> the<br>
> exclusive use of the intended recipient(s). If you are not the intended<br>
> recipient(s) please note any distribution, copying or use of this<br>
> communication or the information in it is strictly prohibited. If you have<br>
> received this communication in error please notify us by e-mail or<br>
> by telephone (as above) and then delete the e-mail and all attachments and<br>
> any copies thereof.<br>
> ______________________________________________________________________<br>
><br>
> _______________________________________________<br>
> Bangalore-pm mailing list<br>
> <a href="mailto:Bangalore-pm@pm.org">Bangalore-pm@pm.org</a><br>
> <a href="http://mail.pm.org/mailman/listinfo/bangalore-pm" target="_blank">http://mail.pm.org/mailman/listinfo/bangalore-pm</a><br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://mail.pm.org/pipermail/bangalore-pm/attachments/20090615/c7591548/attachment.html" target="_blank">http://mail.pm.org/pipermail/bangalore-pm/attachments/20090615/c7591548/attachment.html</a>><br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
Bangalore-pm mailing list<br>
<a href="mailto:Bangalore-pm@pm.org">Bangalore-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/bangalore-pm" target="_blank">http://mail.pm.org/mailman/listinfo/bangalore-pm</a><br>
<br>
End of Bangalore-pm Digest, Vol 16, Issue 8<br>
*******************************************<br>
</blockquote></div><br></div>