scripting languages

Eric Wald eswald at brainshell.org
Mon Nov 8 12:29:49 MST 2010


Kenneth Burgener wrote:
> Alex Esplin wrote:
>> While it's true that you can write clean, easy-to-understand and
>> maintain code in Perl, it takes more effort to do so than in Python.
>> While it's also true that you can script anything in Python that you
>> can in Perl, sometimes Perl's backtick (``) operator and built-in
>> regex capabilities make it a lower-friction interface to automating
>> system scripts.
>
> I agree with Alex on the power of Perl.
>
>
> I like to think of the transition like this: (depending on the size of
> script I need)
>   Bash - Perl - Python

I second this.  If Bash is sufficient, then let it do the job.  It's
particularly well-suited to string commands together, farming the real
work to find, xargs, grep, cut, sort, and sed.  I occasionally use make
to organize such scripts, but only when called for.  If you happen to
know awk, feel free to use it, but at that point I usually skip to perl.
My latest Perl experience has actually been a one-liner from a shell
script, using the convenient -p, -e, and -i flags.

Where Perl shines is single-file scripts that process a bunch of text
input, calling system commands if necessary.  Its huge win over bash+sed
is structured variables.  Its win over Python is terse syntax for system
calls, regular expressions, logic shortcuts, and line-wise reading.  A
mature module in CPAN will tempt me, though I haven't always had the
best experience installing them.

Python is great for standalone programs, particularly if a set of
programs can share logic via subroutines.  I routinely use its built-in
modules for data migrations, and XML processing.  It has worked well for
me as a server for a project-specific protocol.  PyPI has almost as much
reach as CPAN, with virtualenv and easy_install making it even more
convenient to use, when they work.  However, Python is in the middle of
a major version transition, and not all modules are available in each
branch; the expected longevity of your scripts may also determine which
version you decide to learn.

Speaking of which, does anyone here really expect to use Perl 6?

For systems programming, a great library of Python generator functions
could come in very handy, but in some ways is the deep end of the pool
for really learning the language.  The good news is that it's easy to
pick up the rest as soon as you need it.

> By the way, this transition logical also works for web development.  I
> like PHP for easy of use and quick development time.  I like Perl for
> sys admin stuff, but I would never use it for web development (even
> though PHP is descended from Perl).  For large enterprise applications,
> Java and other tools may be more appropriate.

PHP is fantastic for a simple dynamic page.  I've used it for larger
applications, but I keep missing Python features that simply make it
better for anything significant.  Namespaces come to mind, as do
first-class functions...

- Eric


More information about the PLUG mailing list