home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!eiffel!eiffel.com
- From: ram@eiffel.com (Raphael Manfredi)
- Newsgroups: comp.lang.perl
- Subject: Re: How to convice awk/sed users to use Perl ?
- Summary: Apology for perl
- Message-ID: <127@eiffel.eiffel.com>
- Date: 9 Sep 92 18:07:35 GMT
- References: <1992Sep9.143629.13571@cbfsb.cb.att.com>
- Sender: ram@eiffel.com
- Organization: Interactive Software Engineering, Santa Barbara CA
- Lines: 88
-
- Quoting swu@att.com from comp.lang.perl:
- >As a Perl beginner, I don't know how to answer the following question raised
- >by my colleagues:
- > I use ksh/awk/sed very well, why bother to spend a lot of time to learn Perl ?
- What's the real advantages of perl over ksh/awk/sed ?
- >
- >I will appreciate any help.
-
- There are multiple facets in your question, upon which I shall try to build
- my argumentation.
-
- To start with, perl has been cleverly designed to integrate most of the
- attractive features from the C, shell, sed and awk into one single language.
- This means you only have to deal with one (hopefully consistent) program
- instead of three of four dissimilar tools, each of them having its own
- conventions and idioms. You don't have to "think C" and then later "think sed"
- or "think awk", you simply "think perl" and are able to easily put your
- ideas in a concrete form. To mention but the most immediate advantages perl
- brings you: reusability, ease of maintenance, uniformity, flexibility.
-
- Perl brings you reusability, not the "true" one object-oriented languages like
- Eiffel would bring you, but still you may encapsulate functions in libraries
- or software components and then share them across your programs. I have to
- concede that the Korn shell brings you that too, since it has functions and
- files can be "dotted" the same way perl "requires" them. However, sed and awk
- lack this possibility.
-
- Perl brings you ease of maintenance. This is a relative notion of course, since
- maintaining a huge perl program may become tricky (for instance, perl does
- not have static scoping -yet-), but I claim it is simpler to maintain a single
- perl program than a set of ksh/awk/sed scripts performing the same operation.
- And it is much easier to abstract things in perl than it is with sed or awk,
- although perl does not currently support recursive data structures very well.
- And perl comes with an interactive debugger, making it "easy" to track down
- possible problems. In particular, you get step by step execution.
-
- Perl brings you uniformity. Since it is one language, the constructs it is
- using are integrating quite well, as opposed to the unpleasant discrepancy
- you get with ksh/sed/awk. Furthermore, you are facing the famous wizard's
- dilemma of choosing the right tool for each part of your software. I don't
- think someone would dare to imagine doing pattern matching in ksh or process
- control in sed, but if you want to do both, then you need at least two
- cooperating parts in your program, one in ksh and one in sed. Communication
- issues left aside, you are faced with a single program using two different
- tools, with different conventions, whereas perl would integrate those two
- parts elegantly.
-
- Perl brings you flexibility. There is generally more than one way to do things
- in perl (i.e. the language is not minimal) but this lets you use whatever
- scheme or idiom you prefer. If you want to impress academics, one-liners are
- usually good, whereas if you strive to design your program elegantly so as to
- please the software engineer people then perl's name space protection via
- packages or dynamic scoping brings you some of the advantages of the object
- oriented world, which, I have been told, is nothing but eyewash :-)
-
- There are some other advantages in using perl, but they have never been the
- decisive factor for me. Nonetheless, they are considered important in the long
- run if you happen to develop a lot of programs and make an heavy use of perl
- scripts and programs (depending on your terminology, but it's six of one and
- half a dozen of the other).
-
- Perl is fast. In fact, perl is optimized for pattern matching (some people say
- it comes from its name, but I don't believe them :-), and depending on your
- application, a perl script can be faster than a corresponding awk script.
-
- Perl is interpreted. But that is also true for all the alternatives you
- mentioned, therefore this is not a true advantage. At least there is no
- big conceptual jump between ksh/awk/sed and perl (since compiled programs
- often have some restrictions which are happily ignored by interpreters).
-
- Perl comes with the source code. This may or may not be an advantage.
-
- Perl is not only a UNIX tool. Apparently perl has been ported to other
- operating systems and platforms like MS-DOG or the Amiga.
-
- Now if your colleagues have something to say in the defense of ksh/sed/awk,
- I would be glad to hear it. Note that I occasionally use sh scripts, or
- mixture of sh/sed/awk, but usually I have a good reason for doing so ;-).
- For instance, the Configure script which comes with perl has to be written
- in shell + sed + awk. Agreed, it could be written in perl and made more
- portable, but then you have a serious bootstrapping problem.
-
- In the hope this will somewhat address your concerns...
- --
- Raphael Manfredi <ram@eiffel.com>
- Interactive Software Engineering Inc.
- 270 Storke Road, Suite #7 / Tel +1 (805) 685-1006 \
- Goleta, California 93117, USA \ Fax +1 (805) 685-6869 /
-