CGI and Perl

Listing 14.5. GD_Logfile.test.


 require Logfile::Apache;
 require GD_Logfile;
 $l = new Logfile::Apache File  => `apache-ncsa.log',
                     Group => [qw(Domain File )];
 Logfile::GD_Logfile::graph($l,Group => File,
                            Sort => Records,
                            ImSize => [640,480],
                            Font => `gdSmallFont'

This is then invoked as

perl GD_Logfile.test > output.gif

Using the sample Apache access log file provided with the Logfile module, called apache-ncsa.log, the resulting graph is output to the output.gif file and looks like Figure 14.1.

That pretty much wraps up our discussion regarding HTTP log files. It's worth mentioning, however, that you also can use the statistics packages that are available, with some modifications, to summarize the data in a log file. Check your nearest CPAN archive and the Modules List for these statistics modules.

Figure 14.1.
Graphical representation of log file data.

Simple ASCII Text Documents Ordinary ASCII text using regular paragraphs is pretty simple to convert to an HTML representation. Such a conversion is usually preferable in appearance to the raw text in the client browser--for any given text document.

While there doesn't seem to be any viable module for performing this task, there is a nice, well-maintained script called txt2html. It uses a simple mapping file, adapted from another Web tools package, to properly extract and format text-form URLs into standard HTML anchors. txt2html also allows you to configure certain parameters in order to control the general format of the output and the decision-making process regarding things that may have multiple meanings within the text document. Again, use your favorite search engine to search for txt2html to obtain this tool.

It's currently archived at but may be on the CPAN at some point in the future. Source Code and Manpages During the installation procedure on UNIX systems, you will need to have Netscape Navigator installed correctly on your system before launching the installer. If you receive an error that the installer is unable to launch Navigator, double check to see if the binary is installed correctly, with the correct permissions for the account you are running the installer from. You also may need to enter the full path to the binary, if it is not correctly in your path. There are a large number of converters for converting C/C++ source code and UNIX manpages to HTML. There are, in fact, so many that it may not be a good idea to try to provide an example here. At this time, there is not a Perl5 module available designed to actually convert various formats to HTML. Thus, until such time as one is formally developed, I'll defer to the definitive list of conversion tools available at Internationalized Content There are a number of specific elements in the HTML spec that map to the international character set. The idea, then, is to parse a document that contains these characters and replace the instances of the hi-bit characters with the corresponding HTML element. Using the libwww modules, this is now quite simple.

You've already seen an example for performing this translation, in the earlier listing for the script, relativize (see Listing 14.4).