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

A Perl program to extract lines from the middle of a file

I've always been a big fan of the Unix head and tail commands, but several times I have wanted to print a range of lines from the middle of a text file -- not just the beginning or end of a file. Not liking the available solutions, I wrote my own.

Here is the source code for a program named "", which prints lines from a text file beginning at the start line you specify and ending at the stop line.

Today is my mother's birthday, but she's in Greece, so happy b-day from a distance mom.

In the rest of the world news, here are a couple of short tips on using Unix/Linux commands:


Linux FAQ: Can you share some examples of how to use the Linux locate command?


Sure. The locate command is used to find files by their filename. The locate command is lightning fast because there is a background process that runs on your system that continuously finds new files and stores them in a database. When you use the locate command, it then searches that database for the filename instead of searching your filesystem while you wait (which is what the find command does).

How to see the permissions and size of a directory

Here's a short story :) on how to look at files and directories on a Unix/Linux computer system. I've seen so many people do this the hard way that I thought I should finally write something about it.

After a few trials and tribulations, I finally have a new search page going. I didn't like some of the side effects of the old search page, so I'm going with a more standard search engine. I'm using the webinator, from thunderstone.

I've really been in the Perl neighborhood for these last few days. Here are two more tips on using regular expressions and escape sequences in Perl:

You can do many crazy things with Perl regular expressions, but many times you just need to use an escape character (or escape sequence) in a regular expression. I'm often asked what escape sequences you can use in Perl regular expressions, so without any further ado, here is a simple list of "special" characters (such as the [Tab] character) can be matched by the Perl regular expressions:

I won't say that this is a complete list, but I think this is a list of the most popular backslash characters (also known as escape sequences) that can be used in Perl strings:

I was looking for a nice program that would let me kill a bunch of related processes on a Windows PC, similar to the way the killall command works on Linux. (I find this very useful when I'm testing apps and I have a bunch of windows open.)

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: