Alvin Alexander | Java, Scala, Unix, Perl, Mac OS X

Summary: A quick tip on how to read Perl command line arguments.

When you're writing a Perl script, command-line arguments are stored in the array named @ARGV.

$ARGV[0] contains the first argument, $ARGV[1] contains the second argument, etc.

$#ARGV is the subscript of the last element of the @ARGV array, so the number of arguments on the command line is $#ARGV + 1.

Here's a quick tabular list of Postgres commands related to listing information about a Postgres database. (Technically these are "psql commands", because you issue these commands from the psql command line program.)

These Postgres commands help you answer questions like "What tables are in this postgres database?", or "What databases do I have within Postgres?" (a handy question when it comes time for spring cleaning), and other questions. Other popular psql commands are related to permissions, indexes, views, and sequences.

Here's an Extreme Programming FAQ I found, from John Brewer and Jera Design. And while I'm spewing links, here's the Patterns Home Page. And one more link to A Learning Guide To Design Patterns.

Postgresql list FAQ: How do I get a list of databases in a Postgresql database?

Just log into your Postgresql database (with the psql command), and then run this command:


(That's a backslash followed by the lowercase letter "L"). This command provides a nice list of all of the Postgresql databases.

I've been working on a Perl module that makes sending email messages a breeze, but one problem I had is that the Perl module MIME::Lite has a nasty way of failing when something goes wrong. I could not "catch" it's errors with die or warn, so after a little research, I found out how to deal with this problem using eval. According to one text, using eval is the only mechanism Perl has for exception handling.

Here's what I was doing that didn't work:

After trying some other approaches, I finally create a Perl program to extract lines from the middle of a file. Just give it the line number to start at, and a second line number to stop at, and this Perl program will print all the lines from the file in that range.

The source code for this Perl program is shown below.

Sample usage: 500 1000 myBigFile > smallerFile

Here's the code for

Ever need a program to extract some lines from the middle of a file, say lines 50-500 of a 10,000 line file? Well, I did, so I wrote one in Perl. Here's the code for ", which lets me extract lines from a file by specifying the firstLine and lastLine that I want printed from a file:

I'm still living in the Perl world, and that's a good thing. Did I mention that Perl rules for text processing?! Perl is the technology that enables "smart news", or whatever I choose to call it (other name candidates: filtered news, robonews, newsbot).

Perl continues to rule the world, at least the text-processing world. The latest example is HTML::TokeParser, which lets me easily extract HREF's from documents. With this much-improved document parser and the search engine set up, I hope some form of smartnews/robonews will be available soon.

The first in hopefully a series of ooa/ood koans: no end user.

OO Koan: You are assigned to work on a project, but you cannot communicate with the end user -- how do you develop the software?

(Answer: Lots of luck. ;)


Another meaning of GRASP: Graphical Representations of Algorithms,Structures, and Processes. Check out the concept of a Control Structure Diagram (CSD) at Auburn University, and how it changes the appearance of your source code. Does it make it easier to view your code? Does it make it easier to read the code of another?

A couple of URLs I don't want to forget: The OpenJMS Project (JMS == Java Message Service); the Grid Engine Open Source Project, promoted by Sun. Grids are cool, now all I need is an app. :)

Yesterday I was reminded of cetus-links. At last check they have over 18,000 links related to the OO world. While I'm in the linkmeister neighborhood, cgi-resources is still a decent reference for Perl programs.

Perl rules! Yesterday I needed a program that would print a file in reverse, i.e., last line first, first line last. Before I could fret "man, how am I going to do this?", a powerful two-line program spewed forth:

@lines = <>;
print reverse @lines;

Life is good.

What's a beanshell? From the source: "BeanShell is a small, free, embeddable, Java source interpreter with object scripting language features, written in Java. BeanShell executes standard Java statements and expressions, in addition to obvious scripting commands and syntax."

Teaching a brief OO class yesterday, I'm reminded of several things, including Argo/Poseidon as a free UMLish tool, and GRASP, which springs from Wirfs-Brock responsibility-driven design.

A quiet little Memorial Day Sunday so far. Had a fun problem with Postgres yesterday. Here's a little ditty on what to do when you get the nasty "duplicate key" error message, and you know it's wrong.

I had an interesting circumstance happen with Postgres (PostgreSQL) and I want to remember how I fixed the problem.

Somehow I had four entries in a database table, but the key for that table thought that there were only two entries. I don't yet know how this happened, but at the time I didn't care, I just needed to get past the problem. The details of the problem, and the fix, follow.

In my case the table name was carrier, and this table and the key were created like this:

While my real job and the search for a motorcycle occupy most of my time, check out the Mono project, an open source implementation of the Microsoft .NET framework. Ad-aware, from Lavasoft is a free tool for removing "spyware" from your Windows PC. If that link doesn't work you can get the download from ZDnet.