Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Nasty... | 8 comments | Create New Account
Click here to return to the 'Nasty...' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Nasty...
Authored by: pmccann on Feb 27, '02 02:08:11AM

Ouch! So (before changing line endings) you were asking poor old perl to run its regex engine over a single line that was 21M "long". That is, that whole file was sitting in a single scalar variable, and it was changing and copying this monster string as the substitutions were made. Sounds like a delicious recipe for S-L-O-W to me!!

It's probably worth noting that you can work with files that have CR line endings quite efficiently by setting the -l flag (that's an 'ell' for line) to the appropriate octal value, in this case 015.

perl -pi -l015 -e 's/foo/bar/' filename

You get a file with the same line endings out the other end, and it should be loads more efficient than the nightmare of the first paragraph!

Cheers,
Paul



[ Reply to This | # ]