Chapter 24. Web Plots with Gnuplot

Lincoln D. Stein

With all the excitement over the things that we can make Perl do, we sometimes lose sight of the fact that Perl’s greatest strength is the ease with which you can use it to glue independent programs together into a single powerful application. This toolkit philosophy, in which large applications are built from many small command-line tools, is the great simplifying principle of the Unix operating system, and one that Perl readily takes advantage of.

This column addresses a case in point. Say you’re interested in seeing the hourly breakdown of accesses to your web site in order to do capacity planning. When does traffic peak and when is it at a minimum? Say that you want to be able to view this data graphically as a bar chart and that you’d like the chart to be generated on the fly from a CGI script. How would you go about doing this?

One approach would be to do all the work in Perl. Running as a CGI script, Perl can parse the server’s access log file, tally up the hourly hits, generate the bar chart using the graphics primitives in the GD or Image::Magick modules, and output the plot as a GIF image. The script would be responsible for drawing the plot axes, calculating the width and position of the bars, creating the X and Y tics, and drawing the labels. Although the job is relatively straightforward, the program would likely take at least half a day to write and debug and would certainly be several pages of code by the time you were ...

Get Web, Graphics & Perl/Tk Programming 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.