Declarative Programming

Before I discuss application architecture further, I want to talk a little bit about programming style. One way you can make your scripts easier to understand is to use a style called declarative programming. Declarative programming, simply defined, involves writing subroutines for all of the discrete tasks in your programs. In other words, rather than writing a long series of code that performs a bunch of different tasks, you write subroutines for each of the individual tasks and call them all in a row.

First, here’s a very short primer on writing subroutines in Perl. Declaring a subroutine is simple:

sub my_subroutine { } 

That’s it. Unlike Java and C, you don’t have to specify which arguments will be passed to your ...

Get Sams Teach Yourself CGI in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.