Here is my code, I picked one of my shorter scripts:
<code>#!/usr/bin/perl -w
# Joe Ruffino Daily WebOpac.pl
# This program will read in a text file, and print it out
# in table format
# Written: January 30, 2004
# Revised: December 09, 2004, Jan 03, 2005
use CGI qw
standard :html3);
use CGI::Carp qw(fatalsToBrowser);
use strict;
##########################################################################
# Set Variables
#
my $ip_hold = 0;
my $sec;
my $min;
my $hour;
my $day;
my $month;
my $year;
my $ip_list;
my $monthfind;
my $monthm;
my $countip;
my $stationip;
my $stationname;
my @stationip;
my @stationname;
my $dayopac;
my $daym;
my $dayopacm;
my $dayfind;
my $headerpage;
my $dayflag;
my $namev;
my $one;
my $two;
my $three;
my $monthcurr;
my $monthnow;
my $countin;
my $countout;
my $ip;
my $date;
my $time;
my $firstp;
my $secondp;
my $thirdp;
my $fourthp;
my $firstip;
my @firstip;
my $sn;
my $count;
my $date_month;
my $date_day;
my $date_year;
my $i;
my $ips;
my @Names;
my %Names;
my $ext_ip;
my %seen;
my $countint;
my $totalcnt;
my $totalline;
my $station_name;
my @opacline;
my %count;
my @staionip;
my $line;
my $opac_month;
my $hold_date;
my $date_cnt;
my $ip_day_cnt;
my $day_array;
my $ip_day_cnt;
my $four;
my @ext_line;
my %day_array;
my %letters;
my $tot_ip_cnt;
my $ip_cnt;
my $four;
##########################################################################
# Subroutine for finding the text month when numerical month is given
#
sub dayfind {
#Setup date field
if ($dayopacm eq "01") {
$dayfind = "January"; }
if ($dayopacm eq "02") {
$dayfind = "February"; }
if ($dayopacm eq "03") {
$dayfind = "March"; }
if ($dayopacm eq "04") {
$dayfind = "April"; }
if ($dayopacm eq "05") {
$dayfind = "May"; }
if ($dayopacm eq "06") {
$dayfind = "June"; }
if ($dayopacm eq "07") {
$dayfind = "July"; }
if ($dayopacm eq "08") {
$dayfind = "August"; }
if ($dayopacm eq "09") {
$dayfind = "September"; }
if ($dayopacm eq "10") {
$dayfind = "October"; }
if ($dayopacm eq "11") {
$dayfind = "November"; }
if ($dayopacm eq "12") {
$dayfind = "December"; }
return $dayfind;
}
##########################################################################
# Subroutine for finding the numerical month when text month is given
#
sub monthfind {
#Setup date field
if ($monthm eq "Jan") {
$monthfind = "01"; }
if ($monthm eq "Feb") {
$monthfind = "02"; }
if ($monthm eq "Mar") {
$monthfind = "03"; }
if ($monthm eq "Apr") {
$monthfind = "04"; }
if ($monthm eq "May") {
$monthfind = "05"; }
if ($monthm eq "Jun") {
$monthfind = "06"; }
if ($monthm eq "Jul") {
$monthfind = "07"; }
if ($monthm eq "Aug") {
$monthfind = "08"; }
if ($monthm eq "Sep") {
$monthfind = "09"; }
if ($monthm eq "Oct") {
$monthfind = "10"; }
if ($monthm eq "Nov") {
$monthfind = "11"; }
if ($monthm eq "Dec") {
$monthfind = "12"; }
return $monthfind;
}
##########################################################################
# Find current Time and Date info
#
($sec,$min,$hour,$day,$month,$year) = localtime(time);
$year = $year +1900;
# ignore used for testing
$ip_list = "OpacIP";
# ignore used for testing
##########################################################################
# Open IP file and test data file
# Then split IP file into IP address and Station Name array's
#
open (LISTIN,"ipnew.txt") || die "Cannot Open File ipadd.txt for
reading: $!";
while (<LISTIN>) {
($staionip[$countip], $stationname[$countip]) = split(/\s+/);
$countip++;
}
$stationip = @stationip;
$stationname = $stationname;
close (LISTIN);
##########################################################################
# If a file name has been given, process the file
#
$line = 0;
if (param()) {
# Set filename entered to a variable
my $dayopac = param("dayopac");
# Split file name into month and day by assuming a dash is there
($dayopacm, $daym) = split(/-/, $dayopac);
if ($daym) { # if there is a 2-digit day
$dayflag = "yes";
# find the text month by sending the 2-digit month
$monthfind = dayfind($dayopacm);
if ($monthfind eq "December") {
#$year = $year -1;
}
$headerpage = "Daily Stats for " . $monthfind . " " . $daym . ",
" . $year;
} else {
# if not a day to be procressed, check to see if it is a month
to
# be processed
$dayflag = "no";
$daym = "01";
# Split file name into process name and month by assuming an
# underscore is there
($namev, $monthm) = split(/_/, $dayopac);
# find the 2-digit month by sending the text month
$monthcurr = monthfind($monthm);
# if current month is equal to the month entered
if ($month eq $monthcurr) { # if it is 1 - 9
if ($month > 9) {
$dayopacm = $month; # set current month to month holder
} else {
# set current month to month holder and append a '0
$dayopacm = "0" . $month;
}
} else {
# if not equal set month entered to month holder
$dayopacm = $monthcurr;
}
# Go to subroutine to find the FULL text month
$monthnow = dayfind($dayopacm);
if ($monthnow eq "December") {
$year--;
}
($one, $two, $three, $four) = split(/\\/, $dayopac);
# Set title for HTML Output page using text month that was found
$headerpage = "Monthly Stats for $monthnow $year";
}
$ip_list .= "_" . $monthm .".txt";
open (OPAC_IP, ">$ip_list") || die "$ip_list open failed: $!";
$opac_month = $dayopac . "_" . $year . ".html";
open (OPAC_WEB, ">$opac_month") || die "$ip_list open failed: $!";
# Append .txt to filename given, and open file for reading
$dayopac .= ".txt";
open (OPAC,$dayopac) || die ($dayopac . " open failed: $!");
# Print title on new HTML page and first line
print OPAC_WEB <<END;
<HTML><HEAD>
<META name="description" content="GBPL Titles with Holds">
<META name="robots" content="nofollow">
<TITLE>WebOpac $headerpage</TITLE>
</HEAD>
<CENTER>
<H1>$headerpage</H1>
END
($ip,$date,$time,$sn) = split(/ +/);
$hold_date = $dayopacm . "-" . $daym . "-" . substr(($year - 1900),
1,2);
$countin = 0; # zero out counter for ip numbers used in an
array
$date_cnt = 0;
$ip_day_cnt = 0;
while (<OPAC>) {
chomp;
$countout++; # count number of records processed
($ip,$date,$time,$sn) = split(/ +/);
# If IP is internal, process
if ($ip =~ /192.168.33/) {
# Split IP in to 4 parts using a period
($firstp,$secondp,$thirdp,$fourthp) = split(/\./, $ip);
# If IP is between 1 and 9, append 00 to it
if ($fourthp > 0 && $fourthp < 10) {
$fourthp = "00" . $fourthp;
} else {
# If IP is between 10 and 99, append 0 to it
if ($fourthp > 9 && $fourthp < 100) {
$fourthp = "0" . $fourthp;
}
}
# Assign IP to an array element
$firstip[$countin] = $fourthp;
# Add 1 to array counter
$countin++;
} else {
if ($date ne $hold_date) {
foreach $ip (sort keys %day_array) {
$ip_day_cnt++;
}
$tot_ip_cnt += $ip_day_cnt;
$ext_line[$line] = "<b><i>" . $hold_date . "</b></i> has <b><i>" .
$ip_day_cnt . "</b></i> unique External IPs.<p>";
$date_cnt = 0;
$ip_day_cnt = 0;
%day_array = " ";
$line++;
}
$ext_ip++;
$letters{$ip} = 1;
$day_array{$ip} = 1;
$date_cnt++;
}
$hold_date = $date;
}
foreach $ip (sort keys %day_array) {
$ip_day_cnt++;
}
$tot_ip_cnt += $ip_day_cnt;
$ext_line[$line] = "<b><i>" . $hold_date . "</b></i> has <b><i>" .
$ip_day_cnt . "</b></i> unique External IPs.<p>";
# print OPAC_IP @Names;
close (OPAC_IP);
foreach $ip (sort keys %letters) {
$ip_cnt++;
}
#print "<p>$ip_cnt";
# Set length of array to variable
$countint = @firstip;
# Tally distinctive ips
foreach $ips(@firstip) {
$count{$ips}++;
}
foreach $ips(sort(keys %count)) {
for ($i = 0; $i <= $countip; $i++) {
if ($ips == $staionip[$i]) {
$opacline[$totalcnt] = "The Station <b><i>".$stationname[$i]."</i></
b> with IP <b><i>".$ips. "</i></b> has visited Opac <b><i>".
$count{$ips}."</i></b> times.\n";
$totalcnt++;
if ( $count{$ips} > $ip_hold) {
$ip_hold = $count{$ips};
$station_name = $i;
}
}
}
}
close(OPAC);
if ($countint == 0) { $totalcnt = 0;}
if ($dayflag eq "yes") {
$totalline = "There are <b><i> " . $totalcnt . "</i></b> total
patron stations used for <b><i>" . $monthfind . " " . $daym . "</i></
b>.";
} else {
$totalline = "There are <b><i> " . $totalcnt . "</i></b> total
patron stations used for the Month of <b><i>" . $monthnow . "</i></
b>.";
}
print OPAC_WEB hr();
print OPAC_WEB p("There are <b><i>" . $countint . "</i></b>
internal IP address hits.");
print OPAC_WEB p("There are <b><i>" . $ext_ip . "</i></b> external
IP address hits.");
# print p("There are <b><i>" . ($countout-$countin) . "</i></b>
external IP address hits.");
print OPAC_WEB p("There are <b><i>" . $countout . "</i></b> total
IP address hits.");
print OPAC_WEB p($totalline);
print OPAC_WEB p("The Station <b><i>".
$stationname[$station_name]."</i></b> has the greatest number of hits
of <b><i>".$ip_hold."</i></b> times.");
print OPAC_WEB p("There are <b><i>" . $tot_ip_cnt . "</i></b> Total
unique External IP hits for All Days in <b><i>$monthnow</i></b>.");
print OPAC_WEB p("There are <b><i>" . $ip_cnt . "</i></b> unique
External IP hits for the Month of <b><i>$monthnow</i></b>.");
print OPAC_WEB "<FONT SIZE=\"4\" COLOR=\"#FFFFFF\">";
print OPAC_WEB "<A NAME=\"int\">Internal<\/A><\/font>";
print OPAC_WEB "<A HREF=\"\#ext\">External Hits<\/a> ";
print OPAC_WEB hr();
for ($i = 0; $i <= $totalcnt; $i++) {
print OPAC_WEB p($opacline[$i]);
}
print OPAC_WEB hr();
print OPAC_WEB "<FONT SIZE=\"4\" COLOR=\"#FFFFFF\">";
print OPAC_WEB "<A NAME=\"ext\">External<\/A><\/font>";
print OPAC_WEB "<A HREF=\"\#int\">Internal Hits<\/a>";
print OPAC_WEB p(@ext_line);
print OPAC_WEB hr();
print OPAC_WEB "</center>";
use CGI; print redirect("$opac_month");
} else {
##########################################################################
# If a file name has not been given, process the file, create webpage
to
# ask for it
#
print header, start_html("Monthly WebOpac"), h1("Monthly WebOpac
Report");
print hr();
print start_form();
print p("Day File: ",textfield("dayopac"), "<b> * form should be
WebOpac_(<i>3-letter Month</i></b>)");
# print p("Check Test: ",checkbox("opaccheck"));
print p(submit("Submit Entry"));
print end_form(), hr();
}
print end_html;</code>