CGI and Perl

Configuration of HyperCalThe Variables File

All of HyperCal's configuration variables are located in a separate file named "variables." By carefully reading over the configuration file, you can get an idea of what HyperCal does and how to configure it. Listing 11.2 shows the "variables" file for HyperCal.

Listing 11.2. Variables and configuration file for HyperCal.

 $version="2.3";
 #  Names of the various program files
 #  Some sites only allow cgi's with a .cgi extension
 #  so you might need to change your file names
 $add_date="add_date.cgi";
 $del_date="del_date.cgi";
 $disp_day="disp_day.cgi";
 $edit_announce="edit_announce.cgi";
 $hypercal="hypercal.cgi";
 $cal_admin="cal_admin.cgi";
 $personal="personal.cgi";
 $change_passwd="change.password";
 # Other files
 $datebook="datebook";
 $hypercal_id="hypercal_id";
 $announce="announce";
 $users_dir="/www/cgi-bin/datebook/users/";
 $user_variables="/www/cgi-bin/datebook/users/USERNAME/variables";
 # variables
 #  Are you running a secure site with personal accounts?
 $multi_user="no";
 $personal_on="no";
 $old=370;
 #  Number of days to keep past dates
 # Your info goes here - dont make this me, please
 $admin="Richard Bowen";
 $admin_mail="rbowen\@databeam.com";
 $admin_uid="rbowen";
 # Person to contact with problems
 $base_url="/scripts/hypercal/";
 # URL of the directory in which these files live
 $title="HyperCal";
 # Title of the calendar.
 $htpass="/www/passwd/.htpasswd";
 $htgroup="/www/passwd/.htgroup";
 #  Location of the .htpasswd and .htgroup files
 #  This will be used only if you are running the security part
 @linkto=("http://www.mk.net/~~MK.net Home Page", "/perl/~~My Perl archive");
 #  Places to provide links to on each page.
 #  This array contains the locations of images for the various
 #  months.  The format is:
 #  "url_for_icon~~url_for_background~~bgcolor~~link~~visited link"
 #  This array must contain 12 elements. Any field where you have
 #  no preference, indicate by "none"
 @month_images=("images/january.gif~~none~~none~~none~~none~~none",
     "images/february.gif~~none~~none~~none~~none~~none",
     "images/march.gif~~none~~none~~none~~none~~none",
     "images/april.gif~~none~~none~~none~~none~~none",
     "images/may.gif~~none~~none~~none~~none~~none",
     "images/june.gif~~none~~none~~none~~none~~none",
     "images/july.gif~~none~~none~~none~~none~~none",
     "none~~none~~none~~none~~none~~none",
     "none~~none~~none~~none~~none~~none",
     "images/october.gif~~none~~none~~none~~none~~none",
     "images/november.gif~~none~~none~~none~~none~~none",
     "images/december.gif~~none~~none~~none~~none~~none");
 1;

Notice which elements of the program are located in the configuration file. The first two blocks define the names of the supplementary programs and the names and locations of various configuration files. These locations are different on different software platforms and flavors of UNIX, so placing them in a configuration file instead of hard coding them into your code significantly increases your ability to easily get your CGI running on different servers. In general, anything that you might want to change, or will change based on the software environment of your CGI, should be defined in a configuration file.

Arrays are a great way to store variables with multiple elements, like the month_images in the
preceding example. Notice that the last line of code uses a return value to verify the successful loading of the file to the main program.