RE: perl and dba

  • From: Herring Dave - dherri <Dave.Herring@xxxxxxxxxx>
  • To: "Oracle-L (oracle-l@xxxxxxxxxxxxx)" <oracle-l@xxxxxxxxxxxxx>
  • Date: Mon, 11 Feb 2013 23:20:09 +0000

Something "pro" for perl that hasn't been mentioned directly (as a must for 
DBAs) is efficiency for row processing.  I write a lot of shell scripts and 
periodically need to parse files (like OSW data).  While shell is very simple 
to pound out, it is insanely slow compared to perl for reading/parsing data.  
Unfortunately I don't know perl well, but I have access to a few simple 
examples that I use to help me (plus Jared's perl book).

DAVID HERRING
DBA
Acxiom Corporation
EML   dave.herring@xxxxxxxxxx
TEL    630.944.4762
MBL   630.430.5988 
1501 Opus Pl, Downers Grove, IL 60515, USA
WWW.ACXIOM.COM  

-----Original Message-----
From: oracle-l-bounce@xxxxxxxxxxxxx [mailto:oracle-l-bounce@xxxxxxxxxxxxx] On 
Behalf Of Matthew Zito
Sent: Monday, February 11, 2013 2:30 PM
To: cdunscombe@xxxxxxxxx
Cc: rjjanuary@xxxxxxxxxxxxxxxx; fuzzy.graybeard@xxxxxxxxx; 
oracle-l@xxxxxxxxxxxxx
Subject: Re: perl and dba

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);
@text = <FH>;
foreach $line (@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@xxxxxxxxx>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
> >
> >
> > --
> > //www.freelists.org/webpage/oracle-l
> >
> >
>
> --
> //www.freelists.org/webpage/oracle-l
> --
> //www.freelists.org/webpage/oracle-l
>
>
>


--
//www.freelists.org/webpage/oracle-l


***************************************************************************
The information contained in this communication is confidential, is
intended only for the use of the recipient named above, and may be legally
privileged.

If the reader of this message is not the intended recipient, you are
hereby notified that any dissemination, distribution or copying of this
communication is strictly prohibited.

If you have received this communication in error, please resend this
communication to the sender and delete the original message or any copy
of it from your computer system.

Thank You.
****************************************************************************

--
//www.freelists.org/webpage/oracle-l


Other related posts: