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


Click here to return to the 'How long is a piece of a string?' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
How long is a piece of a string?
Authored by: pmccann on Feb 27, '02 07:59:08AM

[[I'm sure this was submitted earlier, but there's no sign of it now. Damn: I really hate reconstructing messages. For what it's worth then...]]

Ouch! The original script you detailed in the hint would have been slinging around a 21MB string (in the $_ variable), shuffling whatever copies are necessary to do the substitution, and so forth: a very effective recipe for making things incredibly S-L-O-W.

You can work with files that have "classic" mac line endings by invoking the "-l" (that's "ell" as in line) option on the command line. It takes an octal value, which in the case of a file with CR line endings should be 015. The nice thing is that the script will use this as default in and out line ending, so that your output file maintains your original line ending character.

That is, you could use:

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

and it should be about as efficient as converting the file first to LF line endings and then running the script.

Cheers,
Paul (waiting for that earlier phantom message to reappear...)



[ Reply to This | # ]
How long is a piece of a string?
Authored by: pmccann on Feb 27, '02 08:03:39AM

Wouldn't you think that almost a decade of web use would drill in the idea of a "cached page"? What a nong! Sorry for the double up: I'm having a bad, bad, day with forums!

Paul ("what does this button do?")



[ Reply to This | # ]