Leo : Examples   Perl Utilities  

Perl is a great language for many things, but one thing it really shines at is in making small programs for system administration. There is a huge library of components for system administration that you can use from Perl, and it is easy to do a lot with a small script.

Scripts that are dashed off quickly to take care of small tasks tend not to be terribly readable and well documented, particularly in a language like Perl that has so many ways to pack a lot of functionality into a few statements. Such scripts also tend to proliferate, since often it can be faster to write a new script than find out whether a script already exists that can do the job.

This tutorial provides an example of how using Leo can solve both of these problems. One sample script is presented, but it is easy to see how adding more scripts to this example outline could result in a package that is very well documented. Addind a new script to this outline would not take much more effort than dashing off a script in a standard text editor.

 


The Leo file used in this tutorial is available from my Leo Resource Page. To download it right-click on this link and choose "Save Target".

Here is how the file looks when first opened.

 


The driveinfo.leo file contains a single script, with documentation and other supplementary files. The script in driveinfo.leo is driveinfo.pl , a Perl script for checking drive space on a Windows machine and then emailing this information to any number of people. (This script doesn't use the newest modules, so it may not be useful for deployment at this point, but still can serve as an illustration of Leo's capability).

If you've downloaded the file and are investigating it with Leo now, you can quickly see that the Leo outline clearly shows what the program is, how to use it, and how it is programmed. Since the benefits of such an outline will probably be immediately obvious, this tutorial will not go into much detail, but will simply point out a few features of the outline.

 


  1. The first node of the outline explains what is in the outline and how to use it.
  2. This node has info about installing the modules necessary to run this script. Most scripts use Perl modules, and not everyone will know how to get and install a Perl module
  3. This node has the actual script.
 


Users of the script will not need to look at the script node, since documentation of how to use it is contained in other nodes. Only progammers who want to change the script will be interested in opening the script node and looking at it.

 


The Driveinfo script is broken down into four sections plus a section for functions. The indicated node is where the script reads the drive space of the drives on the current machine.

Some people claim that Perl is hard to read, but anyone with a basic knowledge of Perl should find the code in this node to be simple to understand.

 


Leo not only makes it easy to deploy a program, it makes it easy to study the program to learn how to implement a particular feature. Let's suppose we aren't interested in drive space, but we do want to write a script to send email. That information is obviously going to be in the indicated node.

 


But apparently that functionality is implemented in the &notify function. We'll have to find and look at that.

 


Since it is a function, we'll expect to find it in this node.

 


The entire function is displayed in the body pane. This is all the code we need to send email using Perl and SMTP module.

 


Text Author: Joe Orr   Copyright 2002 All Rights Reserved  
  Created with ScreenBook Maker   Last update: 8/4/2002   Additional Trademark and Copyright Information