Re: Perl versus UNIX Korn Shell
Like Anthony Esposito in Nov 2003, I had a need recently to persuade some folks to use Perl rather than Unix shell and remembered this old thread. I've summarized my arguments at: http://www.perlmonks.org/?node_id=668481 Feedback welcome. Thanks, /-\ Get the name you always wanted with the new y7mail email address. www.yahoo7.com.au/y7mail
Re: Perl versus UNIX Korn Shell
On Mon, Feb 25, 2008 at 12:57:41PM -0800, Andrew Savige wrote: Like Anthony Esposito in Nov 2003, I had a need recently to persuade some folks to use Perl rather than Unix shell and remembered this old thread. I've summarized my arguments at: http://www.perlmonks.org/?node_id=668481 Feedback welcome. Thanks, /-\ Much of my recent book (see .sig below) is dedicated to demonstrating how Korn/Bash/POSIX shell scripts can either benefit tremendously from Perl's assistance or be replaced entirely by Perl scripts. For a free sample, download the Scripting Techniques chapter from http://minimalperl.com/#Downloads *-* | Tim Maher, PhD (206) 781-UNIX http://www.consultix-inc.com | | tim at ( Consultix-Inc, TeachMeLinux, or TeachMeUnix ) dot Com| *-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+---* | Minimal Perl for UNIX People has been an Amazon Best Seller! | | * Download chapters, read reviews, and order at MinimalPerl.com * | *-*
Re: Perl versus UNIX Korn Shell
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Anthony Esposito) writes: How would you convince someone that programming in Perl is better than using the UNIX Korn Shell? I need some 'intellectual ammo' to convince my colleagues that Perl is a better, more powerful language, to do our scripting. Any suggestions? Gee, the question sounds a bit like, How would you convince someone that a Lamborghini Countach is better than a bicycle? (Yes, I know there are times a bicycle is better... that's part of the point.) Oracle Developer, Enterprise Business Intelligence There you go. Ask your colleagues to come up with a Korn shell script that serializes objects to a relational database. -- Peter Scott http://www.perldebugged.com/ *** NEW *** http//www.perlmedic.com/
Re: Perl versus UNIX Korn Shell
Tim Maher [EMAIL PROTECTED] writes: [...] This means shell programmers have to learn other technologies to get any real work done, and for UNIX/Linux folks, the best choices are Perl, Awk, and then grep/sed/sort/find/tr/col/dd/m4, etc. Someone had mentioned that there is no CPAN for the shell. Well perhaps the collection of standard commands plus any other local programs could be viewed as the modules for shell expansion. I know that they're not collected, nor comprehensive, but it certainly is a rich set of pieces that can be knitted together with a shell script. -- Michael R. Wolf All mammals learn by playing! [EMAIL PROTECTED]
Re: Perl versus UNIX Korn Shell
Esposito, Anthony [EMAIL PROTECTED] writes: How would you convince someone that programming in Perl is better than using the UNIX Korn Shell? I wouldn't. I use both. Here's one argument -- the titles of my reference books for each. Programming Perl, 3rd edition, Wall, Christianson Orwant Programming Perl, 2nd edition, Wall, Christianson Schwartz The KornShell Command and Programming Language, Bolsky Korn Perl is a programming language. KornShell is a command language. KornShell is also a programming language, but I only use the programming language features as they pertain to a command language. For me, that means that I use them in tandem: -- Perl is my programming language. -- KornShell is my command processing language. I use KornShell to glue together my individual tools that I create out from Perl. For creating complex data structures, traversing them, and reporting out, Perl is unlimited. KornShell's data structures are limited to files, lines, and fields. No encapsulation. No inheritance. No extensible types. In short, KornShell is not a programming language in any modern sense of the word. But that's OK, it really wasn't meant to be a complete programming language, only to add enough programming language concepts to leverage the other parts that it's great at -- I/O redirection, file globbing, variable command interpolation, job control, process control, etc -- the kinds of things that are awkward to do within a Perl program. Sure, Perl can do scripting. I just knew enough KornShell to avoid having to do it in Perl. Sure, KornShell can do programming. I made my living as a C programmer at Bell Labs for much of the 80's and 90's by *avoiding* C to do it in KornShell. (Some would say that I never was a C programmer since I tried to avoid to so often.) I could get a lot of things done with a little KornShell gluing together some Unix utilities with and a bit of KornShell programming language magic. But this architecture it would only scale so far. After that I'd have to use AWK, but that, too, had limitations that prevented scaling my applications. I had almost resigned my programming practice when I found Perl -- an elegant blend of the strength of a programming language and the flexibility of a scripting language. Perl is a real programming language, despite it's original appellation, often used belittlingly, as a scripting language. With Perl, I never ran into the limitations I found with Korn or AWK. AWK is gone from my list of active languages (though I'll maintain an AWK script in AWK), but Korn and Perl are a great combination. I need some `intellectual ammo' to convince my colleagues that Perl is a better, more powerful language, to do our scripting. Any suggestions? In summary, Perl is better than KornShell and it isn't. Perl is a better *programming* language. KornShell is a better *command* language. Use 'em both. I hand out a quote card at the beginning of every programming language class I teach. It's a computer scientist quoting a linguist. (Note that Larry is *both* -- a useful combination in my mind -- for someone who's designing a language for both computers and humans.) I use the quote to launch a discussion that brings in all the other languages the students have used and how they have used them. By painting a big picture of the entire programming ecosystem, I then narrow the focus to what the language-du-jour does well, what it doesn't do well, and how it complements other languages in the students' repertoire. It sets the context for the following few days where we concentrate on one specific language, and it prevents some jihad with chants and jibes of my language is better than your language. Perhaps. Better at what? Language shapes the way we think, and determines what we can think about. -- B. L. Whorf -- as quoted in the Preface to the First Edition of The C++ Programming Language, Bjarne Stroustrup * If what you're thinking about is data structures, use a programming language like Perl (or C, or C++, or the BASIC in Visual Basic). * If what you're thinking about is a GUI, use a GUI tool or language (like TK, or the visual in Visual Basic). * If what you're thinking is rules based, use make or some declarative rules-based language. * If what you're thinking is business oriented, use COBOL. * If what you're thinking is (device driver|security|...) use fill-in-the-blank. I happen to think that most of the problems I tend to solve can be divided into two separate parts and that Perl and KornShell map nicely into those two parts -- Korn is the shell that wraps my Perl, which encapsulated the irritation (i.e. problem or business need). Enjoy, Michael -- Michael R. Wolf All mammals learn by playing! [EMAIL PROTECTED]
Re: Perl versus UNIX Korn Shell
Ben Okopnik [EMAIL PROTECTED] writes: [...] As a small comparison, one of my students had a shell script that processed a pair of files, about 75MB each, by doing _something_ (I don't remember the exact details) that involved taking a line from file1 and doing something to every line in file2 based on it, then moving down a line in file1 and repeating the process (note that this was done on some very fast and powerful Sun hardware.) According to his literally shell-shocked account on the third morning of a week-long Perl course, the time to run the script went from over 20 minutes to under 45 seconds when it was rewritten in Perl. Rewriting, by the way, only took him about ten minutes - the script was not very complex. I, too, have engineered, written, debugged, and completed entire Perl programs that completed before their original shell script implementations did. There's something to be said for the right tool and the right algorithm. -- Michael R. Wolf All mammals learn by playing! [EMAIL PROTECTED]
Re: Perl versus UNIX Korn Shell
--On Wednesday, November 05, 2003 15:44:17 -0600 Jonathan Scott Duff [EMAIL PROTECTED] wrote: On Wed, Nov 05, 2003 at 04:19:44PM -0500, Esposito, Anthony wrote: How would you convince someone that programming in Perl is better than using the UNIX Korn Shell? I need some 'intellectual ammo' to convince my colleagues that Perl is a better, more powerful language, to do our scripting. Any suggestions? :-) Legitimate of control structures for one; not having to deal with intermediate storage to capture the output of sed/awk/grep; access to OO; the ability to run shell commands if necessary; compiled language rather than interpreted. -- Steven Lembark2930 W. Palmer Workhorse ComputingChicago, IL 60647 +1 888 910 1206
Re: Perl versus UNIX Korn Shell
On Wed, Nov 05, 2003 at 04:19:44PM -0500, Esposito, Anthony wrote: How would you convince someone that programming in Perl is better than using the UNIX Korn Shell? I agreed with many of the comments others gave on this thread, regarding how each has its merits. To summarize a bit and add my own spin, I'd emphasize that there's very little that can be accomplished with any shell by itself, given that they are command and flow controllers foremost, rather than flexible data processing tools. This means shell programmers have to learn other technologies to get any real work done, and for UNIX/Linux folks, the best choices are Perl, Awk, and then grep/sed/sort/find/tr/col/dd/m4, etc. The choice of Perl is unique amongst this group because those who learn enough about it don't have to learn the dozens of other utilities that other shell programmers must master to accomplish the same tasks. (I used to say the same thing about AWK, but it's since been eclipsed by Perl in this department.) And as an extra bonus, Perl programming skills are portable to other OSs. Along these lines, I'd like to mention that I'm currently writing a book (see .sig) whose goal is to make it easy for shell users and programmers to acquire Perl skills, by focusing on a subset of the language, and embracing Perl through a gradual, incremental approach. For example, it starts out by showing how simple Perl commands can function as better versions of grep, sed, sort, find, awk, etc., and then moves on to show how knowledge of shell programming can be translated into Perl programming techniques. Assuming I ever finish it* 8-}, the book should become available sometime in 2Q 2004, from Manning Press. -Tim P.S. Believe the rumors! Writing a book is *MUCH* harder than it seems/looks/appears/should-be/deserves-to-be, no matter how close you might think your previous projects have resembled the task. And the pay is terrible! 8-{ ** | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | UNIX Fundamentals Class: 11/10-13 Perl Class: 12/01-05 | | Watch for my Book: Minimal Perl for Shell Programmers | **
Perl versus UNIX Korn Shell
How would you convince someone that programming in Perl is better than using the UNIX Korn Shell? I need some intellectual ammo to convince my colleagues that Perl is a better, more powerful language, to do our scripting. Any suggestions? J Tony Esposito Oracle Developer, Enterprise Business Intelligence XO Communications Plano, TX 75074 Ph: 972-516-5344 Email: [EMAIL PROTECTED]
Re: Perl versus UNIX Korn Shell
Shell scripting is just that. Scripting. Its difficult to make reusable code and even more difficult to extend. Perl is a full featured programming language. It works wells with the UNIX Shell and is often used in place of scripting languages. I got my start converting shell scripts to perl scripts. Today, I program in perl. I have all the luxuries of a full featured programmming language with the overwhelmingly fast development time of a shell scripting language. Besides, ask your colleagues to add logging facilities to their scripts, then ask them to log to a DB. Point the to the CPAN for a while. If you do start employing perl, start out on the right foot, use strict and use warnings (-w) and have your colleagues do the same. You'll reap the rewards the first time you have to go back and edit some of their code. Really, what arguments do they have to stick to ksh? On Wed, Nov 05, 2003 at 04:19:44PM -0500, Esposito, Anthony wrote: How would you convince someone that programming in Perl is better than using the UNIX Korn Shell? I need some `intellectual ammo' to convince my colleagues that Perl is a better, more powerful language, to do our scripting. Any suggestions? J Tony Esposito Oracle Developer, Enterprise Business Intelligence XO Communications Plano, TX 75074 Ph: 972-516-5344 Email: [EMAIL PROTECTED] References 1. mailto:[EMAIL PROTECTED] -- Brad Lhotsky [EMAIL PROTECTED]
Re: Perl versus UNIX Korn Shell
On Wed, Nov 05, 2003 at 04:19:44PM -0500, Esposito, Anthony wrote: How would you convince someone that programming in Perl is better than using the UNIX Korn Shell? I need some `intellectual ammo' to convince my colleagues that Perl is a better, more powerful language, to do our scripting. Any suggestions? J Well... the right tool for the right job, I'd say. If the scripting you're speaking of is limited to basic filesystem functions, no real math of any sort, and very simple parsing, then the Korn shell is fine. When extended with a few tools - grep, cat, 'bc, sed, and awk - Korn is actually quite powerful. However, shell scripts are _very_ slow, and any loops that process largish amounts of information can get pretty horrendous. There are endless things you can do with Perl where the shell would just barely limp along, or simply be unable to accomplish the job at all, but if your colleagues are seriously trying to compare the two, then I suspect that the scope of what you're doing probably does not include those. As a small comparison, one of my students had a shell script that processed a pair of files, about 75MB each, by doing _something_ (I don't remember the exact details) that involved taking a line from file1 and doing something to every line in file2 based on it, then moving down a line in file1 and repeating the process (note that this was done on some very fast and powerful Sun hardware.) According to his literally shell-shocked account on the third morning of a week-long Perl course, the time to run the script went from over 20 minutes to under 45 seconds when it was rewritten in Perl. Rewriting, by the way, only took him about ten minutes - the script was not very complex. For myself, I've used a mix of Bash and Perl (10/90) to do literally every scripting task I've needed to accomplish for the past N years (I'm feeling too lazy to battle my forgettery at the moment. :) I wouldn't want to be without either one, but if had to, Perl would be the winnah and champeen. * Ben Okopnik * okopnik.freeshell.org * Technical Editor, Linux Gazette * -*- See the Linux Gazette in its new home: http://linuxgazette.net/ -*-
Re: Perl versus UNIX Korn Shell
On Wed, Nov 05, 2003 at 04:19:44PM -0500, Esposito, Anthony wrote: How would you convince someone that programming in Perl is better than using the UNIX Korn Shell? I need some 'intellectual ammo' to convince my colleagues that Perl is a better, more powerful language, to do our scripting. Any suggestions? :-) AFAIK ksh doesn't have anything like modules or CPAN. You could start there. Nor does ksh have anything like perlmonks. Nor are there proverbial butt-loads of books on ksh. ksh's regular expression features aren't anywhere near as rich as Perl's (but whose is?) Also, last time I checked (it's been years) ksh was *much* slower than Perl. But don't hold too much stock in that notion as implementations do vary. If you're going to pull the speed card, benchmark the two on the systems you are using. As far as raw language features goes, you'll probably get bogged into a Turing equivalence argument fairly quickly. Especially since David Korn himself has said things like ksh has replaced perl for most of our needs (or words to that effect). One thing you might want to do (in the spirit of holding your enemies closer) is look at the ksh advocacy and see where it falls short. For instance: http://slashdot.org/articles/01/02/06/2030205.shtml hope this helps, -Scott -- Jonathan Scott Duff [EMAIL PROTECTED]
Re: Perl versus UNIX Korn Shell
On Wed, Nov 05, 2003 at 04:19:44PM -0500, Esposito, Anthony wrote: How would you convince someone that programming in Perl is better than using the UNIX Korn Shell? I need some 'intellectual ammo' to convince my colleagues that Perl is a better, more powerful language, to do our scripting. Any suggestions? :-) I'd forego the 'intellectual ammo' -- you shouldn't shoot your colleagues (well not usually :-) -- and arguing makes people defensive: Just convince them by solving problems better and faster and sooner than they can in shell. It works better than proselytizing. I'm doing that at work: several people have borrowed books or articles from me after seeing an app or a one-liner that did just what they wanted: they wanted to do do cool things too! If you do want ammo, my war-story is: I'm doing some Perl courses at IBM in the UK, Perl is *the* scripting language used for writing tests and product builds for MQ, the SSA disk group ... and the Java development group. Their main requirements are a common language across all platforms: none of this :- case `echo X\c` in X?c)ECHON=-n ;; *) ECHOC='\c' ;; esac echo $ECHON Some prompt: $ECHOC or case `uname -o` in Solaris) # ... ;; AIX)# ... ;; HPUX) # ... ;; esac which doesn't work on OS/400, OS/2 and Win32 'cause there's no shell ... Best wishes -- Chris Benson
Re: Perl versus UNIX Korn Shell
Esposito, Anthony wrote: How would you convince someone that programming in Perl is better than using the UNIX Korn Shell? I need some intellectual ammo to convince my colleagues that Perl is a better, more powerful language, to do our scripting. Any suggestions? J The shell doesn't do most of the work. Mostly, you're calling external programs, like grep, cat, sort, etc. These don't all have a consistent interface, and they differ from one system to another. Plus, you'll likely end up having to learn sed and/or awk. Why learn all these different tools, plus perhaps two additional languages (sed and awk)? It's all available in Perl, plus much more, including a nice debugger. And well-written Perl scripts are portable. BTW, if you insist writing a shell script and need something like awk, why not use Perl instead of awk? There are a few cases where I would favor bash over Perl - when it's easier to call several existing utilities than to install additional Perl modules (avoid the clutter of those system(...) calls), and when I have a very short script that needs to redirect its output to a file. -- Danny R. Faught Tejas Software Consulting http://tejasconsulting.com/
Re: Perl versus UNIX Korn Shell
Chris Benson wrote: If you do want ammo, my war-story is: I'm doing some Perl courses at IBM in the UK, Perl is *the* scripting language used for writing tests and product builds for MQ, the SSA disk group ... and the Java development group. Their main requirements are a common language across all platforms: none of this :- case `echo X\c` in X?c)ECHON=-n ;; *) ECHOC='\c' ;; esac echo $ECHON Some prompt: $ECHOC or case `uname -o` in Solaris) # ... ;; AIX)# ... ;; HPUX) # ... ;; esac which doesn't work on OS/400, OS/2 and Win32 'cause there's no shell ... Here's another war story. You want to find the home directory and shell of user $myuname. $HOME and $SHELL environment variables are unreliable (especially if running via su). The best I could come up with is: myhome=`csh -fc echo ~$myuname` myshell=`egrep ^$myuname: /etc/passwd | sed -e 's/^..*:\(..*\) *\$/\1/'` But some Linux systems don't have csh. And using /etc/passwd is unsound -- what if they are using NIS+, say? True, I'm not up-to-date with the latest Korn shell (it may have a way to solve this); I tend to use /bin/sh if I need high portability (i.e. Korn shell and/or Perl may not be installed) and Perl for everything else. In Perl, this problem is easily and soundly solved by calling the getpwnam() function. Larry summarizes it with: It is easier to port a shell than a shell script I have written many cross-platform shell scripts, but it is much easier to do in Perl. Joseph N Hall sums it up in Effective Perl Programming, Introduction: Can you write cross-platform shell scripts? Yes, but with extreme difficulty. Most mere mortals should not attempt such things. Can you write cross-platform Perl scripts? Yes, easily. Another point not mentioned yet is that Perl is far superior to shell for writing secure scripts: it relies much less on forking external commands and has a unique taint mode feature. Just curious: why do they prefer Korn shell over bash, say? /-\ http://personals.yahoo.com.au - Yahoo! Personals New people, new possibilities. FREE for a limited time.