Re: Need to improve throughput - Any thoughts



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

.



Relevant Pages

  • Re: "Gender-free masculine pronoun"? Absurd. [was: Re: Crossposting [was: Re: Traditional
    ... That is, the grammatical gender of English is based on sex, unlike the ... Ships and cars being referred to as "she" is an affectation, ... That is, someone might speak of their own car, ... > ships, airplanes, and females are 'she' ...
    (sci.lang)
  • Re: XP newbie woes
    ... >>could substitute an English version for a Spanish version? ... > And when I bought my car here in Spain, ... > purpose, but not *my* purpose. ...
    (microsoft.public.windowsxp.basics)
  • Re: XP newbie woes
    ... >>could substitute an English version for a Spanish version? ... > And when I bought my car here in Spain, ... > purpose, but not *my* purpose. ...
    (microsoft.public.windowsxp.basics)
  • Re: Renault "Fisichella not at fault - tyre wear was the problem"
    ... > helped Kimi and Alonso. ... In English ... > from the opening laps and putting a lot of energy through his tyres. ... In English <Flavio as usual gave Alonso the better car and it did look ...
    (rec.autos.sport.f1)
  • Re: Bizarre Newsnight Story About England Flags and Racial Hatred
    ... covered with *ngland flags in Gallowgate, Glasgow, and filmed ... The car was duly attacked by 5 thugs. ... You guys are the one making the big deal out of the car having English ... clear to all the world that the English and the Scots hate one another, ...
    (soc.culture.scottish)