in reply to hashes performance issue
It's not surprising that your loop is taking a long time. You're duplicating every hash in your HoHs, for every token in your token table. And it is completely unnecessary.
This will probably run an order (or two) of magnitude faster:
for $a (sort keys %mstrToken) { $df = 1; foreach $doc ( @docNames ) { if( exists $hash2{ $doc }{ $a } ) { $mh{$a}->{ docf } = $df++; $mh{$a}->{ $doc } = $hash2{ $doc }{ $a }; } } }
That said, you really ought to consider using more descriptive names for your variables. If $a was $token, things would be much clearer. And %hash2? Is that the second hash in this program? Or the second one this week; decade; century?
While your at it, move to use strict;. It's not obligatory, but you'll be glad you did in the long term.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hashes performance issue
by stan131 (Acolyte) on Mar 29, 2009 at 04:50 UTC |