Jim Gibson <jimsgib...@gmail.com> writes:

Harry wrote:
>> Shawn, hoping to pester you once more about this topic.

Jim G responded:
> It is not fair to single out Shawn for help. Just post your question
> and hope for a response.

Just a manner of speaking, but you're right it does appear to be a
little off the wall.  It wasn't my intent to elicit responses from
only Shawn... It was just that he was the one who authored the nifty
inversion sub routine.

[...] 

Jim wrote:
> Using only "inverted" hashes (untested):
>
>   for my $file ( sort keys %inv_d1h ) {
>     if( exists $inv_d2h{$file} ) {
>       print "Duplicate file names found: ", scalar @{$inv_d1h{$file}},
>        " in $d1 and ", scalar @{$inv_d2h{$file}}, " in $d2\n";
>       print "\n$d1:\n    ", join("\n    ",@{inv_d1h{$file}}), "\n";
>       print "\n$d2:\n    ", join("\n    ",@{inv_d2h{$file}}), "\n";
>     }
>   }

Haven't gotten to try this yet... but it made me wonder right off why
I'd want to do that.  I'm on my way out the door in a moment but
curious now... about your reasoning.

Also eager to put that into a real script and try it out. You've made
a neat job  of it.

Is there some gain in doing it with both hashes inverted?  Does it
simplify things in some way, or is it mainly an example of another way
to go at it?

It doesn't seem to take much time at all to do the inversion, seems
more or less instantaneous in fact.  That surprised me a bit, when one 
of those hashs has something like 4000 lines.

I noticed quite a marked gain comparing my original approach to the
code you were responding to in your message above.

Originally went something like this (not actual code):

  foreach my $keyd1 (keys %d1h){

     foreach my $keysd2 (keys %d2h){
        if($d1h{ $keyd1 } eq $d2h{ $keyd2 } {
              push @matches, $d2h{ $keyd2 };
        }
     }
     ## process @matches 
        dispatch_table($dh1{ $keyd1 }, @matches);
  }

That really puts the whammy on resources since it marches some 4000
possible matches for each line of %d1h (which is a nearly 2000 lines)
through the gauntlet. 8,000,000 or so lines in the actual event.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to