home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5802 < prev    next >
Encoding:
Internet Message Format  |  1992-09-09  |  5.3 KB

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