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">&lt;<a href="mailto:bangalore-pm-request@pm.org">bangalore-pm-request@pm.org</a>&gt;</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 &#39;help&#39; 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 &quot;Re: Contents of Bangalore-pm digest...&quot;<br>
<br>
<br>
Today&#39;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 &lt;<a href="mailto:mkirank@gmail.com">mkirank@gmail.com</a>&gt;<br>
Subject: Re: [Bangalore-pm] Need Help to optimise the code<br>
To: Srinivas Reddy &lt;<a href="mailto:SReddy@securities.com">SReddy@securities.com</a>&gt;<br>
Cc: &quot;<a href="mailto:bangalore-pm@pm.org">bangalore-pm@pm.org</a>&quot; &lt;<a href="mailto:bangalore-pm@pm.org">bangalore-pm@pm.org</a>&gt;<br>
Message-ID:<br>
        &lt;<a href="mailto:b2d58a680906151430l1622dfaam9d711a6982cb1068@mail.gmail.com">b2d58a680906151430l1622dfaam9d711a6982cb1068@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;windows-1252&quot;<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>
    &#39;row&#39; =&gt; 33,<br>
    &#39;col&#39; =&gt; 1,<br>
    &#39;value&#39; =&gt; &#39;xx&#39;,<br>
},<br>
<br>
{<br>
    &#39;row&#39; =&gt; 30,<br>
    &#39;col&#39; =&gt; 1,<br>
    &#39;value&#39; =&gt; &#39;zz&#39;,<br>
},<br>
<br>
{<br>
    &#39;row&#39; =&gt; 34,<br>
    &#39;col&#39; =&gt; 1,<br>
    &#39;value&#39; =&gt; &#39;yy&#39;,<br>
},<br>
<br>
);<br>
<br>
my @arr1 =(<br>
<br>
{<br>
    &#39;row&#39; =&gt; 33,<br>
    &#39;col&#39; =&gt; 1,<br>
    &#39;value&#39; =&gt; &#39;xx&#39;,<br>
},<br>
<br>
{<br>
    &#39;row&#39; =&gt; 30,<br>
    &#39;col&#39; =&gt; 1,<br>
    &#39;value&#39; =&gt; &#39;zz&#39;,<br>
},<br>
<br>
{<br>
    &#39;row&#39; =&gt; 35,<br>
    &#39;col&#39; =&gt; 1,<br>
    &#39;value&#39; =&gt; &#39;yy&#39;,<br>
},<br>
<br>
);<br>
<br>
<br>
my @vals =  map {$_-&gt;{&#39;row&#39;} &gt; 32 &amp;&amp; $_-&gt;{&#39;col&#39;} &gt; 0 ?stringify(%$_):()}<br>
@arr;<br>
my @vals1 =  map {$_-&gt;{&#39;row&#39;} &gt; 32 &amp;&amp; $_-&gt;{&#39;col&#39;} &gt; 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 &quot;@_&quot;;<br>
}<br>
<br>
<br>
<br>
<br>
2009/6/15 Srinivas Reddy &lt;<a href="mailto:SReddy@securities.com">SReddy@securities.com</a>&gt;<br>
<br>
&gt;  Hi Thnx a lot for your quick help. Sry C is rules out as this willl form<br>
&gt; a part of perl script and we have ?C? Expertise issue as well. I think<br>
&gt; kumars solution would really help . Let us rewrite it and check the<br>
&gt; performance.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; I am still looking at a function which takes 2 arrays and gives me the<br>
&gt; difference in them , in my case these array contain my xls file ( row , col<br>
&gt; and value associated with each cell ) .<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Regards,<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Srinivas Reddy<br>
&gt;<br>
&gt; Asia Technology and Global Projects Manager<br>
&gt;<br>
&gt; Skype : sreddyisi<br>
&gt;<br>
&gt; Cell : +91 9740076449<br>
&gt;<br>
&gt; LandLine : +91 9900524073/74/76./78<br>
&gt;<br>
&gt; Fax : +91 8026729764<br>
&gt;<br>
&gt; Url : <a href="http://www.securities.com" target="_blank">www.securities.com</a><br>
&gt;<br>
&gt; <a href="http://www.thefinancialnet.com" target="_blank">www.thefinancialnet.com</a><br>
&gt;<br>
&gt; <a href="http://elearning.securities.com" target="_blank">elearning.securities.com</a><br>
&gt;<br>
&gt; P Please consider the environment before printing this email<br>
&gt;   ------------------------------<br>
&gt;<br>
&gt; *From:* <a href="mailto:simrangambhir@gmail.com">simrangambhir@gmail.com</a> [mailto:<a href="mailto:simrangambhir@gmail.com">simrangambhir@gmail.com</a>] *On<br>
&gt; Behalf Of *simran<br>
&gt; *Sent:* Monday, June 15, 2009 6:17 PM<br>
&gt; *To:* Srinivas Reddy<br>
&gt; *Cc:* <a href="mailto:bangalore-pm@pm.org">bangalore-pm@pm.org</a><br>
&gt; *Subject:* Re: [Bangalore-pm] Need Help to optimise the code<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Hi Srinivas,<br>
&gt;<br>
&gt; The code is not very complex, and unless you change the structure, it will<br>
&gt; not optimise too much... better to write it neatly (and with better arg<br>
&gt; passing... as suggested in the email by Ravish.<br>
&gt;<br>
&gt; If you are looking for absolute speed, better to write in in C and plug it<br>
&gt; in via XS.<br>
&gt;<br>
&gt; simran.<br>
&gt;<br>
&gt; 2009/6/15 Srinivas Reddy &lt;<a href="mailto:SReddy@securities.com">SReddy@securities.com</a>&gt;<br>
&gt;<br>
&gt; Hi ,<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Please help to optimize the code below.  We basically read 2 xls files into<br>
&gt; an array @xls2 and @xls1 . For each cell we want to compare ( starting from<br>
&gt; col 32 ) values in each cell and if they are not equal we need to store it<br>
&gt; in a different array. This we will then use to bold those particular cells.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; The loop which does this comparison could be replacement by some in built<br>
&gt; array difference kind of function. I am new to perl so apologies if I ve<br>
&gt; used any wrong terminologies here.  Appreciate your help on the same. Please<br>
&gt; find attached whole code as well for reference<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; sub cell_handler2 {<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;         my $workbook    = $_[0];<br>
&gt;<br>
&gt;         my $sheet_index = $_[1];<br>
&gt;<br>
&gt;         my $row         = $_[2];<br>
&gt;<br>
&gt;         my $col         = $_[3];<br>
&gt;<br>
&gt;         my $cell        = $_[4];<br>
&gt;<br>
&gt;              # Construct array for Dx code<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;         push @xls2 , {<br>
&gt;<br>
&gt;                         &#39;row2&#39; =&gt; $row,<br>
&gt;<br>
&gt;                         &#39;col2&#39; =&gt; $col,<br>
&gt;<br>
&gt;                         &#39;value2&#39; =&gt; $cell-&gt;value(),<br>
&gt;<br>
&gt;         };<br>
&gt;<br>
&gt;         return @xls2;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; }<br>
&gt;<br>
&gt; #print Dumper(@xls2);<br>
&gt;<br>
&gt; # Print the End Time to read second excel file<br>
&gt;<br>
&gt; print scalar(localtime) . &quot;: End Reading Excel2 \n&quot;;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; print scalar(localtime) . &quot;: Start Populating Bolding Array \n&quot;;<br>
&gt;<br>
&gt; # Inefficient way of looping<br>
&gt;<br>
&gt; # Please change this as it could boost the performance significantly<br>
&gt;<br>
&gt; for(@xls2) {<br>
&gt;<br>
&gt;             if($_-&gt;{&#39;col2&#39;} &gt; 32 &amp;&amp; $_-&gt;{&#39;row2&#39;} &gt; &#39;0&#39; ) {<br>
&gt;<br>
&gt;                                     $newvalue = $_-&gt;{&#39;value2&#39;};<br>
&gt;<br>
&gt;                                     $newrow = $_-&gt;{&#39;row2&#39;};<br>
&gt;<br>
&gt;                                     $newcol = $_-&gt;{&#39;col2&#39;};<br>
&gt;<br>
&gt;                                     for(@xls1) {<br>
&gt;<br>
&gt;                                                 $oldrow = $_-&gt;{&#39;row1&#39;};<br>
&gt;<br>
&gt;                                                 $oldcol = $_-&gt;{&#39;col1&#39;};<br>
&gt;<br>
&gt;                                                 if($_-&gt;{&#39;col1&#39;} &gt; 32 &amp;&amp;<br>
&gt; $_-&gt;{&#39;row1&#39;} &gt; 0 &amp;&amp; $_-&gt;{&#39;row1&#39;} eq $newrow &amp;&amp; $_-&gt;{&#39;col1&#39;} eq $newcol) {<br>
&gt;<br>
&gt;<br>
&gt; $oldvalue = $_-&gt;{&#39;value1&#39;};<br>
&gt;<br>
&gt;<br>
&gt; last;<br>
&gt;<br>
&gt;                                                 }<br>
&gt;<br>
&gt;                                     }<br>
&gt;<br>
&gt;                                     if($oldvalue ne $newvalue) {<br>
&gt;<br>
&gt;                                                 push @bold_array , {<br>
&gt;<br>
&gt;                                                             &#39;row&#39; =&gt;<br>
&gt; $_-&gt;{&#39;row2&#39;},<br>
&gt;<br>
&gt;                                                             &#39;col&#39; =&gt;<br>
&gt; $_-&gt;{&#39;col2&#39;},<br>
&gt;<br>
&gt;                                                             &#39;value&#39; =&gt;<br>
&gt; $_-&gt;{&#39;value2&#39;},<br>
&gt;<br>
&gt;                                                 };<br>
&gt;<br>
&gt;                                     }<br>
&gt;<br>
&gt;             }<br>
&gt;<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Regards,<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Srinivas Reddy<br>
&gt;<br>
&gt;<br>
&gt; ______________________________________________________________________<br>
&gt; This communication contains information which is confidential. It is for<br>
&gt; the<br>
&gt; exclusive use of the intended recipient(s). If you are not the intended<br>
&gt; recipient(s) please note any distribution, copying or use of this<br>
&gt; communication or the information in it is strictly prohibited. If you have<br>
&gt; received this communication in error please notify us by e-mail or<br>
&gt; by telephone (as above) and then delete the e-mail and all attachments and<br>
&gt; any copies thereof.<br>
&gt; ______________________________________________________________________<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Bangalore-pm mailing list<br>
&gt; <a href="mailto:Bangalore-pm@pm.org">Bangalore-pm@pm.org</a><br>
&gt; <a href="http://mail.pm.org/mailman/listinfo/bangalore-pm" target="_blank">http://mail.pm.org/mailman/listinfo/bangalore-pm</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; ______________________________________________________________________<br>
&gt; This communication contains information which is confidential. It is for<br>
&gt; the<br>
&gt; exclusive use of the intended recipient(s). If you are not the intended<br>
&gt; recipient(s) please note any distribution, copying or use of this<br>
&gt; communication or the information in it is strictly prohibited. If you have<br>
&gt; received this communication in error please notify us by e-mail or<br>
&gt; by telephone (as above) and then delete the e-mail and all attachments and<br>
&gt; any copies thereof.<br>
&gt; ______________________________________________________________________<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Bangalore-pm mailing list<br>
&gt; <a href="mailto:Bangalore-pm@pm.org">Bangalore-pm@pm.org</a><br>
&gt; <a href="http://mail.pm.org/mailman/listinfo/bangalore-pm" target="_blank">http://mail.pm.org/mailman/listinfo/bangalore-pm</a><br>
&gt;<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: &lt;<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>&gt;<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>