It's no secret that I am in love with Perl. I can honestly say that it is my favorite scripting language. To me, it is clean, powerful, efficient, concise, and everything that I want a scripting language to be. I can also say that my favoritism toward Perl is not because of a lack of experience with other scripting languages. I have used Python extensively and have used my fair share of Ruby, along with several others.
Lately, I have been giving a fair amount of attention to Ruby for a few reasons. First, we have a new programmer at work and since Ruby is one of the only languages that he knows, I am helping him when he gets stuck. The structure, syntax and semantics are clear enough that I am able to point out logic errors and traps in a language that I, admittedly, am not an expert in (though I have had three separate programming language concept classes). Second, there are some times that I can just knock out a quick script in a few lines without needing to worry about all of the error catching and process killing that I do (out of habit) in Perl. Now, don't get me wrong, I love the Perl syntax shown below, but there is something nice about the Ruby syntax, too. I guess that what I am getting at, in a very roundabout way, is that even if you commit yourself fully to a given language, realize that one language will never do everything that you would like as easily as you would like. In order to appreciate a language, you need to know when to use it and when to use something else.
For example, if I am writing a loooong script using several database connections to several types of databases (Oracle, DB2, mySQL) and I need to know everything that is going on at any given moment, I am more familiar and comfortable using some Perl like:
#!/usr/bin/perl
use strict;
use warnings;
use locale;
use DBI;
my $dbh = DBI->connect('DBI:Oracle:'.'DBNAME', 'acctName','passwd',
{AutoCommit => 1}) or die print "Unable to Connect\n";
my $selectstmt = "SELECT val1,val2...valn FROM ROOT.AE_X_EMPL_X WHERE (E_STAT = 'A')";
my $sth = $dbh->prepare($selectstmt)
or die print "Unable to prepare the Dept User Select Stmt.: " .
$dbh->errstr . "\n";
$sth->execute()
or $errMsg = $sth->errstr;
while(@data= $sth->fetchrow_array()){
do stuff;
}
$dbh->disconnect();
If I am writing a script that I am using to perform nested selects within a single database, then I a would probably be more likely to use Ruby. The reason is that I can usually tell pretty quickly if my data is coming out right in a situation like this. It isn't that I don't trust Ruby, I am just more comfortable with my Perl syntax. But, for the Ruby, notice how much shorter the syntax is for a similar situation:
#!/usr/bin/ruby
require 'oci8'
oracleConnection=OCI8.new('acctName','passwd','DBNAME')
db=oracleConnection.exec("select deptnum, dept_desc from tbw_depthead order by deptnum")
while var = db.fetch()
do stuff
end
oracleConnection.disconnect
See? Much, much simpler syntax overall.
But, I guess that the whole point of this is that you need to understand your tools to understand the best way to solve a problem. Imagine a carpenter using a sledgehammer to drive finishing nails into a baseboard. Doesn't seem like a good idea does it? How about using a screwdriver as a wrench? Exactly. Bad idea. I know that Perl's Regex support is pretty much the best that I have found, but I also know now (from experience) that cgi and css support is much easier/clearer in Ruby. Finally, I am going to leave this as an open ended post and try to get some feedback from you guys about your scripting preferences and what you like to use different scripting languages for. Lat me know....