Introduction to Ajax

In this article, I provide an explanation of Ajax with a historical introduction and WITHOUT the use of any frameworks such as jQuery. If you are eager to start seeing the code, please scroll down.


What is Ajax?

Ajax stands for Asynchronous Javascript And XML. It’s a way to call back-end scripts asynchronously – that is, without impacting user experience/flow. Basically, you don’t even see the cursor become an hourglass or whatever other “waiting/processing” icon your system uses. It’s not a language, but a technique. As for back-end scripts, you can use whatever you feel more comfortable with: PHP, Perl, Java, JSP, Shell, C, etc. The way to choose which technology to use as back-end is outside the scope of this article.

 Historical approach for calling back-end apps

Throughout web-development history, the very first way used to achieve back-end processing followed by front-end display was to create a form and set the back-end script as the action to that form. Upon submission, the form fields would be sent to the back-end script as a series of special environment variables, which would then be handled by the programmed logic. The back-end output would be displayed on the screen (either the same page/frame or a different page/frame, depending on the target attribute of the form).

The catch 22 of this approach is that if you want to present another form after processing, that form must be produced by the back-end script, which leads to maintenance mayhem – to add or remove a field, you have to do so in both the original HTML and in the HTML of the back-end script.

Continue Reading…

Install DBD::Oracle and Oracle Instant Client on Ubuntu

Update: If you’re looking for instructions for Ubuntu 12.04 and later, most of the steps below still apply, but there are a few small differences nicely explained by Rob Staveley at

Update 2: It turns out these steps can be used for Cygwin as well. Thanks to Marc for pointing it out.

A couple of weeks few years ago I finally got a new laptop at work – which meant of course that I had to reinstall everything. Although we used Windows XP, there was one app that I had to run through Linux. The solution was VirtualBox running Ubuntu. When I tried to run the app, I realized that I still needed to Install DBD::Oracle and Oracle Instant Client on Ubuntu – which brings me to this article. Nothing better than a reinstall to generate article material 🙂

DBD::Oracle is usually a pain to install if you haven’t already done it a gazillion times. After that, it’s just an annoying itch. In this article I’ll cover installing DBD::Oracle using Oracle Instant Client, Ubuntu 9.04 (at the time – I’ve had reports that this works on 12.04 and up), and Perl 5.10. Since we’re using the Instant Client, you’ll need an Oracle DB you can connect to in order to do the testing. You can choose to skip testing altogether, but you might be into an unpleasant surprise later. Continue Reading…

Recursion with Perl and CDS

Update: Changed subroutine to comply with Perl Best Practices

Update2: Removed the prototype from the subroutine.

I’ve always had a problem with recursion. Not with the general theory that a function will call itself, etc – no, that’s easy. The hard part was when I had to deal with complex data structures in Perl (an array- or hashref containing a hash of arrays of hashes, a gazillion levels deep). Well, I guess anyone would have a hard time with that kind of data.

Anyway, in this post I don’t intend to get all complicated explaining all the kinds of recursions out there. If you want that, check this article at wikipedia. What I do want to do is help all of those who are in the situation I was in, by explaining in the simplest way possible how to deal with this scenario. Continue Reading…

How to Use MQSeries with Perl

Today I managed to finally get Perl to put and get messages to MQ Series. It’s something that I’ve been wanting to do for quite some time, but didn’t have the time or even MQ knowledge to do so.

This post is intended for those who, like me, aren’t MQSeries gurus and can’t make much of the documentation of the MQSeries module in CPAN. I hope it serves you well and in the end you will be able to use MQSeries with Perl. Continue Reading…

Perl Crash Course: Pragmas, Perl Modules, and CPAN

I always like to say that 90% of Perl is its modules. Back in 2000 when I was working as a junior Perl programmer I was asked to write a web application that, among other things, could send contact messages through email. Unfortunately, I never had anyone to really teach me the Path of Perl – I only relied on Learning Perl by Randall Schwartz, and whatever I could find on the net. I had a really hard time with that application, mainly because I didn’t know about Perl modules, MySQL and SQL language. Had I been familiar with at least the Perl modules part, I wouldn’t have had to spend 8 days and nights in the office (including my birthday). I didn’t even know how to use strict; at the time! Keep reading if use strict; makes no sense to you.

Being the extensible and flexible language that it is, Perl provides us with some safeguards and helpers to assist in avoiding what happened to me (I wish I knew that back then). The first of which I’ll talk about is Pragmas.
Continue Reading…

Perl Crash Course: Basic I/O

author: Valeria Paixão
revision: André Batosti
enhancement/translation: Vinny Alves

Note from UseStrict: Some of the examples in this tutorial were borrowed from Randall Schwartz’s Learning Perl. It’s a book that EVERY beginner Perl programmer should have. If you don’t have a hardcopy, please consider getting one. You can find it here: Learning Perl, 5th Edition


In this article, you will learn how to use basic I/O in Perl, learn about @ARGV, and become familiar with string formatting using printf.


<STDIN> tells Perl to read from the standard input – usually the keyboard.

while (defined($_ = <STDIN>)) {
	print "I saw $_";  # echoes whatever is typed onto the screen. 
                                # Quit with ^D or ^Z (depending on your system)

foreach (<STDIN>) { 
        print "I saw $_"; # almost the same as above

The difference between the while and foreach loops above is that while executes its statements at every hit of the return key, while foreach slurps into memory all the input until eof (^D on Unixes) and only then executes its instructions.

It is important to note this difference if you don’t want to crash your machine. If your input comes from a webserver with a 400MB log file, you’re better off processing each line individually than slurping it all into memory.
Continue Reading…

Perl Crash Course: File and Directory Tests and Manipulation

by André Batosti
revision: Vinny alves

Opening Files

To read or write files in Perl, you need to open a filehandle. Filehandles in Perl are yet another kind of identifier.
They act as convenient references (handles, if you will) between your program and the operating system about a particular file. They contain information about how the file was opened and how far along you are in reading (or writing) the file. They also contain user-definable attributes about how the file is to be read or written.

To open a new file on system you need to create the filehandle for this file using the command open

open(filehandle, pathname);

The filehandle is the identifier that will describe the file and the pathname – the full path of the file you trying to open. Typically it is represented by a constant, but when working with complex programs, it is best to use a scalar variable in order to safely pass it from one subroutine or method to another.

Continue Reading…

Perl Crash Course: Control Structures

by André Batosti
revision: Fernando Giorgetti and Vinny Alves

Control Structures are used to control the flow of a program. We are going to see programs that can iterate (loop) or make decisions (conditionals) based on the state of variables.

More interesting possibilities arise when we introduce control structures and looping. Perl supports lots of different kinds of control structures which tend to be like those in C, but are very similar to Pascal, too.
Continue Reading…

Perl Crash Course: Basic Regular Expressions

Coming soon, a revamped version of this article. Sorry for the inconvenience.

« Gettin’ jiggy wit it | TOC | Control Structures »

Perl Crash Course: Subroutines


Subroutines are user-created functions that execute a block of code at any given place in your program. It is a best practice, however, to aggregate them all either at the beginning or the end the main program.

Subroutine declarations initiate with the key word “sub” . Conventionally, subroutine names are all lowercase characters


print_hello; # subroutine can be executed/called before the actual block is created

sub print_hello {
      print "Hello world\n";

When we called print_hello we told Perl that we wanted the piece of code named print_hello to be executed. The result is a “Hello World” showing up on our screen. The only benefit we have from that snippet in its current form is that we won’t have to copy/paste the print statement all over our script if we want to repeat it. All we need to do is call print_hello;
Continue Reading…