Re: Need to improve throughput - Any thoughts
- From: usenet@xxxxxxxxxxxxxxx
- Date: 27 Feb 2006 15:16:25 -0800
Gladstone Daniel - dglads wrote:
I have a text file with around 1 million lines and I need to do a search
And replace on over 9000 words. I am currently reading a line and
passing A hash table against it...
We could help you more if you would post actual code instead of an
English description of it. English is ambigious, but Perl is precise.
You also don't show us what your data looks like (is it freeform text
with punctuation characters, etc? Do you have singular/plural word
forms to deal with? Does uppercase/lowercase matter? etc, etc, etc). It
really does matter.
Something like this might be OK for a start (without knowing more about
the data); refinement may be necessary to suit the actual data:
#!/usr/bin/perl
use strict; use warnings;
my %change = qw/Fred Fredrick
drives peddals
car vehicle
Barney Bernard
log tree/;
while (my $line = <DATA>) { #or your actual filehandle
$line =~ s/$_/$change{$_} || $_/e for (split /\s+/, $line);
print $line;
}
__DATA__
Fred drives the Flintstone family car
Barney has a car that looks like a log
car Car cars car's cargo encarta Nascar - only first 'car' matches!
--
http://DavidFilmer.com
.
- References:
- Need to improve throughput - Any thoughts
- From: Gladstone Daniel - dglads
- Need to improve throughput - Any thoughts
- Prev by Date: Re: Need to improve throughput - Any thoughts
- Next by Date: RE: num to alpha
- Previous by thread: Re: Need to improve throughput - Any thoughts
- Next by thread: RE: Need to improve throughput - Any thoughts
- Index(es):
Relevant Pages
|
|