Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Simply Too Slow Find and Replace

by krazken (Scribe)
on Jun 03, 2002 at 18:27 UTC ( [id://171299]=note: print w/replies, xml ) Need Help??


in reply to Simply Too Slow Find and Replace

I would go about it a little different. I would read your find/replace table into a hash with the find value as the key of the hash. Depending on the amount of memory on your box you are running this with, you may need to tie this has to a file in order to accommodate the data. With find/replace type stuff, I have found better performance with DB_BTREE instead of DB_HASH. Using this approach on a 4 processor 4GB ram server, I have processed close to 12 million an hour. By doing this way you would have something like:
#pseudo code open lookup file while(<lookup>) { chomp; my ($find,$replace)=split /=/; $hash{$find}=$replace; } close lookup open file to work on while(file) { my $field_to_lookup_on=split/unpack whatever if(exists $hash{$field_to_lookup}) { $new_field=$hash{$field_to_lookup}; } else { $new_field=$field_to_lookup_on; } put field back in record print record.
This method does away with looping through arrays and puts it into a little better of a data structure. let me know if this doesn't make sense. kudos. krazken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://171299]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-05-21 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found