mdi has asked for the wisdom of the Perl Monks concerning the following question:
I need to do multiple substitutions in several large (1-10MB) files. I've been using this:
...but this is taking entirely too long, and using up too much CPU. How can I do this more efficiently?use strict; use warnings; use Tie::File; foreach my $x (@ARGV) { tie my @f, 'Tie::File', $x or die "Could not tie $x: $!\n"; for (@f) { s/^\|/\\N\|/; s/\|\s*$/\|\\N/; s/\|\s*\|/\|\\N\|/g; s/\|\.\s*\|/\|\\N\|/g; s/\|\s+/\|/g; s/\s+\|/\|/g; s/(\d{2}:\d{2}:\d{2})\.\d+/$1/g; s/(\d{5})-(?:\d{1,4}|\s+)/$1/; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Multiple substitutions in large files
by Joost (Canon) on May 09, 2005 at 13:48 UTC | |
Re: Multiple substitutions in large files
by dragonchild (Archbishop) on May 09, 2005 at 13:46 UTC | |
by ikegami (Patriarch) on May 09, 2005 at 14:41 UTC | |
Re: Multiple substitutions in large files
by ikegami (Patriarch) on May 09, 2005 at 14:58 UTC |
Back to
Seekers of Perl Wisdom