You're only iterating over hashes, not using the lookup features. If you do it properly, you'll increase the speed of the loop roughly by the number of elements in %hash2.
while(my ($key1,$value1)=each(%hash1)){
while(my ($key2,$value2)=each(%hash2)){
if($key1 eq $key2){
...
}
}
Should be better (and faster!) written as
while(my ($key1,$value1)=each(%hash1)){
if (exists $hash2{$key} ) {
my $value2 = $hash2{$key}
...
}
}
Also note that this code:
foreach(@allhits){
while(my $str=<FH1>){
exhausts the <FH1> iterator for the first value in @allhits, and does nothing for the subsequent values - probably not what you want.
Likewise I don't see how you ever get items into @file2. (Update: I should have looked more carefully)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|