Re: perl and dba

From: Matthew Zito <matt_at_crackpotideas.com>
Date: Mon, 11 Feb 2013 15:29:55 -0500
Message-ID: <CAJ7936woP1BRK-_9G8o3ugGh_bqyZ67LWfQ2UK8MKfox08eVYA_at_mail.gmail.com>



I have spent most of my career working with Perl to one degree or another - I picked it up way back in the day when I realized that I was writing various things in shell scripts, then adding more and more features by request to them, until it was a horrifying shell script CGI web interface to log parsing or something similar. So I just started writing things in Perl.
We ended up writing all of the business logic for our product (formerly GridApp, now BMC Database Automation) in Perl, so I've seen what perl can do on a small and large scale. Recently I've been banging out Python code, so it's been an interesting transition.

The good things about Perl:
- Amazing regular expression and text processing support

  • Flexible syntax means you can hack together a script in whatever fashion you want
  • Perl's "guess what you mean" capabilities also make it easy to write quick and dirty code
  • Huge library of 3rd party modules means that what you need to do is probably written somewhere by someone else.

The bad things about Perl:
- Flexible syntax means that 7 different ways to do the same thing makes
for complicated and hard to read code and forces you to spend a lot of time on coding standards when you're trying to make something maintainable
- Flexible syntax also means that all those modules on CPAN are written
differently, with different interfaces, etc.
- OO in Perl is terrible - trying to support both procedural and OO coding
in the same language resulted in the solomonic beauty of the baby being cut in half
- Perl being weakly typed is a huge time-saver when it works, but when it
doesn't, or you have to troubleshoot what's going on, it's a nightmare

For example, let's say I wanted to open a file, read it, and change all occurrences of "cat" to "dog". I can do it several ways:

#!/usr/bin/perl

$file = "test.txt";

print "#1 \n";
open(FH,$file);
while(<FH>) {

        $_ =~ s/cat/dog/;
        print $_ ;

}
close(FH);
################

print "#2 \n";
open(FH,$file);
_at_text = <FH>;
foreach $line (_at_text) {
        $line =~ s/cat/dog/;
        print $line;

}
close(FH);
################

print "#3 \n";
use FileHandle;

my $fh = FileHandle->new("$file");

while( $line = $fh->getline) {

        $line =~ s/cat/dog/;
        print $line;

}
$fh-close();
################

So - all three of those are functionally equivalent, and all use totally different approaches for reading the data. This is great from a convenience perspective, but terrible from a maintainability perspective.  It's a real problem.

Python, by contrast, isn't nearly as flexible, but is really elegant and simple:

file = open("test.txt")

for line in file:

        print line.replace("cat", "dog")

I like both languages - but if I were starting from scratch today, I'd probably learn Python, despite my deep love of Perl.

Matt

On Mon, Feb 11, 2013 at 3:47 AM, Chris Dunscombe <cdunscombe_at_yahoo.com>wrote:

> I too prefer Python with cx_oracle. I find Python so much easier to read
> and maintain compared to perl.
> Chris
>
>
> ________________________________
>
> Python, numpy, matplotlib, and cx_oracle have become "must haves" on my
> laptop. At this point I've at least broken even on the amount of time
> spent learning python vs the time I've saved using it and it's modules.
>
> I respect perl as a language, but it's not for me.  At times I found it
> difficult to maintain scripts if I didn't revisit them regularly.  As a
> crutch I ended up with a gratuitous amount of in line comments.  I don't
> seem to have the same issue with python.
>
>
> On 02/08/2013 02:47 PM, Hans Forbrich wrote:
> > On 08/02/2013 11:09 AM, Jared Still wrote:
> >
> >> Shell is fine for relatively simple Oracle stuff, that is, where work is
> >> done in the database.
> >> ...
> >> If any complex work is required that cannot easily be satisfied with
> >> PL/SQL, Perl is my tool of choice.
> >>
> > Oracle seems to agree with you:
> >
> >      [ls | dir] $ORACLE_HOME/sysman/admin/scripts
> >
> >
> > --
> > http://www.freelists.org/webpage/oracle-l
> >
> >
>
> --
> http://www.freelists.org/webpage/oracle-l
> --
> http://www.freelists.org/webpage/oracle-l
>
>
>


--
http://www.freelists.org/webpage/oracle-l
Received on Mon Feb 11 2013 - 21:29:55 CET

Original text of this message