Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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

Comment on Re^3: Massive regexp search and replace
Download Code

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 drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2015-10-13 19:30 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (314 votes), past polls