[wplug] Perl script - need help

Zach netrek at gmail.com
Wed Jan 23 14:36:54 EST 2008


Hi,

Writing my first CGI script (also my first Perl script!) and I'm
getting some unexpected results.

First probem:

The ip and browser type etc are printed out in the browser on one line
with no newline yet I included "\n\n"

Second problem:

In my log file the ip is printed on first line, then newline, and on
3rd line is the browser type etc.  This is all good, except
each time the script is run it over-writes the previous information.
So instead of making lines 4,5,6 it just over-writes lines 1,2,3

Any help in debugging this would be appreciated.

Here is my script:

#!/usr/bin/perl
# script to log IP and other interesting visitor info

$log_file = "/afs/club.cc.cmu.edu/usr/chaos/www/test/ip.foo8.txt";
$ip = $ENV{'REMOTE_ADDR'};
$agent = $ENV{'HTTP_USER_AGENT'};
$fp = open (LOG, ">$log_file"); # opens the log file for writing
flock(LOG, 2); # file lock set
print LOG "$ENV{'REMOTE_ADDR'} \n\n";
print LOG "$ENV{'HTTP_USER_AGENT'} \n\n";
flock(LOG, 8); # file lock unset
close(LOG);
print "Content-type: text/html\n\n";
print "Your Ip was logged.....$ip\n\n";
print "Your Agent is..........$agent\n\n";

Zach


More information about the wplug mailing list