perl to python
Roy Smith
roy at panix.com
Tue May 11 08:47:53 EDT 2004
Oliver Fromme <olli at haluter.fromme.com> wrote:
> FWIW, sed _is_ a state machine, although not really "general
> purpose". It is a programming language with variables, loops
> and conditionals, and I believe it is turing-complete. Most
> of the time it is abused to perform simple search-and-replace
> tasks, though. ;-)
I would disagree that the "simple search-and-replace" usage is abuse.
It's just using the tool to do what it's best at. Sure, there are some
more complex things you can do in sed, but the syntax is so baroque it
quickly becomes trying to bash a screw with a hammer.
In the old days, when the task became too complicated for sed, you
switched to awk. When things got even more complex, you pasted sed,
grep, awk, and shell together in various ways, and perl was invented to
cover all those functionalities in a single language.
In a sense, perl suffers from the same disease that C++ does; a desire
to maintain backwards compatability with its parents (thus the absurdly
eclectic syntax) while at the same time adding every new feature you
could imagine (and some that you can't).
Anyway, I think there's a lot of value in learning tools like grep and
sed, and using them when appropriate. The example that started this
thread is the canonical example of what sed does best. Sure, you can
make a general-purpose tool like Python do that job, but other than
proving that you can do it, I don't see any reason to bother.
More information about the Python-list
mailing list