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

Cool, I've been back to Perl for a few days. I'd forgotten what a cool language it is. Here are two brief Perl tips related to my recent work:

Summary: How to use Perl here documents, i.e., the Perl heredoc syntax.

Perl offers a convenient way of printing multiple lines of output through an interesting feature known as a "Perl here document". A here document, or heredoc, lets you easily store multiple lines of text in a Perl variable.

A multiline Perl here document works like this:

Summary: Using the Perl backtick operator to execute system comands

One of the real strengths of the Perl programming language is the ease in which you can access (execute) the commands of the underlying operating system. As other programming languages point out, this can be considered a weakness, because it also makes your programs system-dependent, but in reality I've found this to be a problem only five or 10 percent of the time. 

Here are some important/useful JBuilder keyboard shortcuts to remember:

JBuilder Open Tools question: Can you tell me some of the best JBuilder Open Tools?

Sure. From the Borland Conference 2001, here is a list of the Top-10 Open Tools for JBuilder:

A note for me for the future: Bob Hope passed away a few days ago. I don't think most people younger than me care about this too much, but I liked his "On the Road" movies, tv specials, and what he did for the people in the military.

Here are a couple of new tips I've written on using regular expressions in Java 1.4. Both tips include complete, working source code examples.

Java multiline pattern FAQ: Can you share an example of a multiline Java pattern (regular expression)?

Enable Java assertions tip: The main thing to remember is that assertions -- new to Java 1.4 -- are not enabled by default. That's true when compiling, and also when running your program.

When compiling your code with javac, you need to compile your source code using the "-source 1.4" option. Then, when running your program you need to specify the "-ea" of the java or javaw command to enable assertions.

Here's a simple but interesting quote from a "Use Case" book I was reading last night: 

"If the actor is not part of the system, then the requirements cannot be a part of the system."

This statement seems obvious, but reflecting on some of my own work I can see where I have occasionally strayed in this direction, and having reviewed the work of other people, I have often seen these types of requirements in requirements documentation.

Enable Java assertions in Ant (FAQ): How do I enable Java assertions in Ant?

Here's something that should have been a little more obvious to me: how to enable assertions when compiling Java code that uses the version 1.4 "assertions" feature:

I just participated in a seminar on the new features in the Java 1.4.2 language, and new planned features for the Java 1.5 language. Here is a list of URLs that I used in the research for that seminar:

Two new items today. First, I've published the Unix Systems Administrator Training Material. I'm not very happy with it in it's current form, but it's out there. (It needs some reformatting work.)

I'm going to live with some monks for the rest of this week and early next week, so things will be quiet here.

This may be a little too touchy-feely for some people, but as I prepare for this trip, the one thing I was struck with this morning is how bad we have been to the Earth since North America was first colonized. Looking at things from the perspective of the Earth, things were pretty good back in the days when the Indians roamed this continent. Since then, we've built all of these cities, "conquered" all of this land, and then polluted the air, land, and water.

Wow, I just learned about the Linux locate command the other day. I'm going to have to quit using find so much. The locate command is very quick, assuming it can find what it's looking for in it's cache.

Here's a quick locate example. Assume that you have apache installed on your system, but you can't remember where it is. Just type locate apachectl to find the apachectl command, and you'll see locate return some output, very quickly, like this:

Java Mail (JavaMail) IMAP FAQ: Can you show me how to get a list of all the email addresses in an IMAP mailbox using the Java Mail API (JavaMail API)?

Sure. Here's the source code for a Java mail (JavaMail) program that extracts all of the "from" fields out of a specified mailbox. This works for both POP3 and IMAP mailboxes.

Before going to the code, note the cool use of a TreeSet (java.util.TreeSet) in this example. Based on our offline discussion, you mentioned that you really want is this:

One other Unix command while I'm in the neighborhood. Somewhat along the lines of what I was doing on Monday -- looking at the size of Apache log files -- I wanted to generate a sorted list of log files for May and June only. Here's how to solve that problem by grouping Unix commands:

(may;jun) | sort +4n

In this example, I'm grouping the commands 'may' and 'jun' together using the parentheses, and piping their combined output into the sort command. With the sort command, I'm sorting numerically by the 5th column.

It looked like one of our servers was getting hit pretty hard a while ago, and since we have about 100 sites on that server, I needed a way to find the largest log file. How to solve this? The Linux find command!

First, cd to your apache log file directory. Next, here's the command that showed me the access log files on our system, sorted in ascending order by size:

find . -name "access*" -mtime -1 -exec ls -ld {} \; | sort +4n

Ahh, brings tears of joy to my eye just looking at it. :)


What are the possible properties you can get from System.getProperty() you might ask ... or in my case, really need to know(!). This URL from a Sun tutorial provides the necessary relief, er, help.


I started the Google AdWords campaign last night. I'm using AdWords to supplement some of the searches where the site does not appear in the first page of search results. One example is when google users search for "unix example", the "www" site does not show up well for some reason. Therefore, I'm spending a little money to buy some exposure. Stay tuned for results...