[29674] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 918 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 9 00:14:16 2007

Date: Mon, 8 Oct 2007 21:14:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 8 Oct 2007     Volume: 11 Number: 918

Today's topics:
    Re: Script not able to work on Server 2003 <jruffino@gailborden.info>
    Re: Script not able to work on Server 2003 <dummy@example.com>
    Re: Script not able to work on Server 2003 <paduille.4061.mumia.w+nospam@earthlink.net>
    Re: The Modernization of Emacs: terminology buffer and  <dkixk@earthlink.net>
    Re: The Modernization of Emacs: terminology buffer and  <zaxfuuq@invalid.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 08 Oct 2007 16:10:46 -0700
From:  Joe <jruffino@gailborden.info>
Subject: Re: Script not able to work on Server 2003
Message-Id: <1191885046.853822.178650@50g2000hsm.googlegroups.com>

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>



------------------------------

Date: Tue, 09 Oct 2007 02:19:20 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: Script not able to work on Server 2003
Message-Id: <IyBOi.10789$Cj1.4762@edtnps90>

Joe wrote:
> 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
> #

You should declare your variables in the smallest scope possible instead of 
all here.

[ SNIP ]


> ##########################################################################
> # Subroutine for finding the text month when numerical month is given
> #
> sub dayfind {
> 
> 	#Setup date field
> 	if ($dayopacm eq "01") {
> 	    $dayfind = "January"; }

> ##########################################################################
> # Subroutine for finding the numerical month when text month is given
> #
> sub monthfind {
> 
> 	#Setup date field
> 	if ($monthm eq "Jan") {
> 	    $monthfind = "01"; }

Just use hashes instead of subroutines:

my %dayfind = qw( 01 January 02 February 03 March 04 April 05 May 06 June 07 
July 08 August 09 September 10 October 11 November 12 December );

my %monthfind = qw( Jan 01 Feb 02 Mar 03 Apr 04 May 05 Jun 06 Jul 07 Aug 08 
Sep 09 Oct 10 Nov 11 Dec 12 );


> ##########################################################################
> # Find current Time and Date info
> #
> ($sec,$min,$hour,$day,$month,$year) = localtime(time);
> $year = $year +1900;

You don't use $sec, $min, $hour or $day so:

my ( $month, $year ) = ( localtime )[ 4, 5 ];
$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;

Shouldn't that be:

my $stationip = @stationip;
my $stationname = @stationname;

But you never use the variables $stationip and $stationname anyway.


> 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;
>       }

         $monthcurr = $monthfind{ ( split /_/, $dayopac )[ 1 ] }
         $dayopacm = sprintf '%02d', $month eq $monthcurr ? $month : $monthcurr;


>       # Go to subroutine to find the FULL text month
>       $monthnow = dayfind($dayopacm);

         $monthnow = $dayfind{ $dayopacm };


>       if ($monthnow eq "December") {
> 	  $year--;
>       }
>       ($one, $two, $three, $four) = split(/\\/, $dayopac);

You never use these variables anywhere?


>       # 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);

      $hold_date = sprintf '%s-%s-%02d', $dayopacm, $daym, $year % 100


>    $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/) {

 >           if ( $ip =~ /^192\.168\.33/ ) {


>               # Split IP in to 4 parts using a period
> 	      ($firstp,$secondp,$thirdp,$fourthp) = split(/\./, $ip);

You never use $firstp, $secondp and $thirdp so ...


> 	      # 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;
> 		}
> 	      }

               $fourthp = sprintf '%03d', ( split /\./, $ip )[ 3 ];


> 	      # 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++;
> 		  }

                   $ip_day_cnt += keys %day_array;


> 		  $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++;
> }

   $ip_day_cnt += keys %day_array;


> $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++;
> }

   $ip_cnt += keys %letters;


> #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>";

Instead of 21 + $totalcnt calls to print() just print once:

     print OPAC_WEB
         hr(),
         p( "There are <b><i>$countint</i></b> internal IP address hits." ),
         p( "There are <b><i>$ext_ip</i></b> external IP address hits." ),
         p( "There are <b><i>$countout</i></b> total IP address hits." ),
         p( $totalline ),
         p( "The Station <b><i>$stationname[$station_name]</i></b> has the 
greatest number of hits of <b><i>$ip_hold</i></b> times." ),
         p( "There are <b><i>" . $tot_ip_cnt . "</i></b> Total unique External 
IP hits for All Days in <b><i>$monthnow</i></b>." ),
         p( "There are <b><i>" . $ip_cnt . "</i></b> unique External IP hits 
for the Month of <b><i>$monthnow</i></b>." ),
         "<FONT SIZE=\"4\" COLOR=\"#FFFFFF\">",
         "<A NAME=\"int\">Internal<\/A><\/font>",
         "<A HREF=\"\#ext\">External Hits<\/a> ",
         hr(),
         map( p( $opacline[ $_ ] ), 0 .. $totalcnt ),
         hr(),
         "<FONT SIZE=\"4\" COLOR=\"#FFFFFF\">",
         "<A NAME=\"ext\">External<\/A><\/font>",
         "<A HREF=\"\#int\">Internal Hits<\/a>",
         p( @ext_line ),
         hr(),
         "</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>


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


------------------------------

Date: Mon, 08 Oct 2007 21:12:34 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: Script not able to work on Server 2003
Message-Id: <13glpah4hokjc63@corp.supernews.com>

On 10/08/2007 06:10 PM, Joe wrote:
> 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"; } [...]

Use data to simplify code (untested):

my @monthnames = qw(
     January February March April May June
     July August September October November December ) ;

my %monthnames;
@monthnames{ @monthnames } = 1 .. @monthnames ;

my %rMonthnames = reverse %monthnames;

sub dayfind {
     $dayfind = $monthnames{$dayopacm};
}

sub monthfind {
     $monthfind = $rMonthnames{$monthm};
     sprintf('%02d', $monthfind);
}


> 
> 	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++;
> }

Huh? Why do you advance the field counter ($countip) each time through 
the loop? Now you get both a different record and a different field with 
each iteration.

> 
> $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);

Dayfind does not use any arguments from its argument list, yet you give 
it an argument anyway--why?

>       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;
>    }
> [...]

I stopped reading here. The large number of global variables you used 
and the large amount of text you posted make it not worth my while to 
continue.

Your program is confusing because its functions are 10x the size they 
need to be to get the job done, and you went hog-wild with the global 
variables.

A debugger is available for Perl, but it'll cost you¹. However, creating 
the right environment for the debugger will be a challenge. If you 
haven't done so already, read the posting guidelines². They suggest 
creating the shortest but runnable program that demonstrates your 
problem; ninety per cent of the time, doing so reveals the bug.

--------------------
¹ $0.00. Try this: perl -d Web0pac.pl
² http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


------------------------------

Date: Mon, 08 Oct 2007 21:28:12 -0500
From: Damien Kick <dkixk@earthlink.net>
Subject: Re: The Modernization of Emacs: terminology buffer and keybinding
Message-Id: <13glppu3hknk597@corp.supernews.com>

Wildemar Wildenburger wrote:
> Frank Goenninger wrote:
>> On 2007-09-29 01:27:04 +0200, Damien Kick <dkixk@earthlink.net> said:
>>
>>> If you were referring to the "free" in "free Mumia Abu Jamal", I 
>>> would agree with you.  I don't think anyone would imagine that this 
>>> phrase meant that someone was going to get Mumia Abu Jamal gratis.  
>>> Like it or not, "free software" referring to "free as in beer" is 
>>> probably the most common interpretation of the phrase for a native 
>>> English speaker. [...]
>>
>> Fully true for non-native English speakers as well. Just did the "wife 
>> test" also - she is a pure software user - and yes, free is "no money, 
>> do what you want" and that's it.

I should have used the phrase "fluent English speaker"...

>> I *never* use the term "free" if I don't want to imply "free beer" 
>> (which is a Good Thing and as such highly valuated - ask any 
>> Bavarian). Using "free" as by FSF or any other lawyer-style 6 pixel 
>> font printed phrasing is pure perfidiousness.
>>
> I appearantly missed a lot of that conversation, but what is your point? 
> While I agree that the word "free" implies "free of monetary cost" to 
> many people societies, that is by no means set in stone [...].

For some odd reason, this reminded me of an old episode of Mork & Mindy:

<blockquote 
cite="http://www.salon.com/ent/movies/feature/1999/09/03/robin/">
What made Mork think eggs could fly? And yet when he tried to release 
them from the tyranny of gravity ("Fly, be free!"), flinging them into 
the air only to have them land with a soft thwack, it seemed like 
nothing so much as a stroke of loopy brilliance.
</blockquote>

The term "free eggs" can only sensibly mean one thing, eggs which can be 
obtained without an exchange of money.  To think of it meaning anything 
else--"fly, be free!"--is comedy (or not, depending on one's opinion of 
Mork & Mindy).  When Free Software Foundationistas try to insist on the 
phrase "free software" meaning anything other than the obvious 
interpretation of the term it is annoying (or not, depending on one's 
opinion of RMS's skills as a wordsmith).  I've got this great mental 
image of some farcical Free Software Liberation Army running around, 
removing hard drives from boxen, and throwing them in the air with the 
moral imperative to "fly, be free!"

> But that aside: The word free with respect to the FSF and GPL have a 
> perfectly well defined meaning. People may misunderstand that from not 
> knowing the definition but that doesnt make it any less well defined.

This thread of conversation also popped into my head when I was waiting 
in line at the Starbucks in the building in which I work.  I've been 
ordering a lot of Americanos lately.  I always ask for a small Americano 
and the person taking my order always calls out my drink as a "tall". 
With respect to Starbucks, calling a beverage which comes in the 
shortest cup used in the store a "tall" has a perfectly well defined 
meaning.  But that doesn't make it any less ridiculous.  Of course, it 
was mentioned elsewhere in this thread that context is important.  And 
it is.  To use the Starbucks analogy, for someone to criticize Starbucks 
because their tall drinks really are actually quite short would be 
ignoring the significance of the context of Starbucks' abuse of the 
English language.  But, again, that doesn't make Starbuck's use of the 
word any less ridiculous.  However, at least at Starbucks, when I use 
the "wrong" word, they don't start lecturing me.  They know what I mean 
and simply go ahead and translate it to Starbucks newspeak.

> Again, why this discussion?

Hello, Pot?  This is the kettle.  You are so black.


------------------------------

Date: Mon, 8 Oct 2007 22:00:27 -0700
From: "Wade Ward" <zaxfuuq@invalid.net>
Subject: Re: The Modernization of Emacs: terminology buffer and keybinding
Message-Id: <D_ednahCQttIYZfanZ2dnUVZ_j-dnZ2d@comcast.com>




"Damien Kick" <dkixk@earthlink.net> wrote in message 
news:13glppu3hknk597@corp.supernews.com...

> This thread of conversation also popped into my head when I was waiting in 
> line at the Starbucks in the building in which I work.  I've been ordering 
> a lot of Americanos lately.  I always ask for a small Americano and the 
> person taking my order always calls out my drink as a "tall". With respect 
> to Starbucks, calling a beverage which comes in the shortest cup used in 
> the store a "tall" has a perfectly well defined meaning.  But that doesn't 
> make it any less ridiculous.  Of course, it was mentioned elsewhere in 
> this thread that context is important.  And it is.  To use the Starbucks 
> analogy, for someone to criticize Starbucks because their tall drinks 
> really are actually quite short would be ignoring the significance of the 
> context of Starbucks' abuse of the English language.  But, again, that 
> doesn't make Starbuck's use of the word any less ridiculous.  However, at 
> least at Starbucks, when I use the "wrong" word, they don't start 
> lecturing me.  They know what I mean and simply go ahead and translate it 
> to Starbucks newspeak.

I, as a tall Americano, have always taken ordering the smallest espresso 
beverage possible as something describing the preference of the orderer, as 
opposed to the beverage itself.

-- 
wade ward
"Your boyfriend is not my boyfriend, doll."




------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 918
**************************************


home help back first fref pref prev next nref lref last post