Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^3: Massive regexp search and replace

by hsinclai (Deacon)
on Feb 10, 2005 at 14:07 UTC ( #429721=note: print w/replies, xml ) Need Help??

in reply to Re^2: Massive regexp search and replace
in thread Massive regexp search and replace

Expanding on Hena's idea I wonder if it would be even more efficient to use Tie::File to go through, writing replacements as you go (untested):
use Tie::File; my $inputfile = "samplein.txt"; &replacer($inputfile); sub replacer { tie my @currentfile, 'Tie::File', $inputfile or die "$!"; my $inputline; foreach $inputline ( $currentfile[0] .. $#currentfile ) { foreach my $key (keys %regex) { $inputline =~ s/$key/$regex{$key}/gee; } } untie @currentfile; } ## Totally untested

Seems like the write operation would be faster with Tie::File

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2016-10-28 13:39 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (383 votes). Check out past polls.