Welcome to WebmasterWorld Guest from 54.145.208.64

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

errors in cgi script run by cron

   
11:22 pm on Sep 21, 2002 (gmt 0)

10+ Year Member



Hi,
I have a couple of scripts that are run by cron and cron emails me about these errors:

Use of uninitialized value in read at access-roll.cgi line 39.

Use of uninitialized value in split at access-roll.cgi line 46.

Use of uninitialized value in string eq at access-roll.cgi line 13.

Lines in question marked with >>>>

###############################################
#!/usr/bin/perl -w
use vars qw(%config %form %02d);
use CGI;
use File::Copy;
local %config;
$config{'basepath'} = '/home/mysite';
$config{'closedir'} = '/home/mysite/access';
require "/home/mysite/access/next.dat";
$nowtime = (time);
$log = 'access-log';
######## Main Program
local %form = &get_form_data;
if ($form{'action'} eq '') { &closeit; } >>>>
else { &closeit; }
#-###################
sub closeit {
open (NEXT, "$config{'closedir'}/next.dat");
($item) = <NEXT>;
close NEXT;
if ($item < $nowtime) {
$nextroll = ($item + 86400);
if ($config{'closedir'}) {
umask(000);
mkdir("$config{'closedir'}", 0777) unless (-d "$config{'closedir'}");
copy ("$config{'basepath'}/$log", "$config{'closedir'}/$item.txt");
open (NEW, ">$config{'basepath'}/$log");
print NEW "";
close NEW;
open (NEXT, ">$config{'closedir'}/next.dat");
print NEXT "$nextroll";
close NEXT;
}
}}
#-#####################
sub get_form_data {
my $temp;
my $buffer;
my @data;
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); >>>>
foreach $temp (split(/&Š=/,$buffer)) {
$temp =~ tr/+/ /;
$temp =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
$temp =~ s/[\r\n]/ /g;
push @data, $temp;
}
foreach $temp (split(/&Š=/,$ENV{'QUERY_STRING'})) { >>>>
$temp =~ tr/+/ /;
$temp =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
$temp =~ s/[\r\n]/ /g;
push @data, $temp;
}
return @data;
}
###############################################

There may be code that I don't need? but I'm not too sure what isn't needed.
Any help appreciated.

4:22 pm on Sep 25, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



any of you perl folk want to take a stab at this?
6:00 pm on Sep 25, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Those are only optional warnings enabled by the -w switch. Perl complains about an undefined value being used as if it were defined.

It seems that youŽll get those warnings if there is no input from STDIN. To exit immediately at the beginning of your script unless $ENV{'CONTENT_LENGTH'} is defined might help.

Andreas

11:52 pm on Sep 25, 2002 (gmt 0)

10+ Year Member



Thanks andreas.

so I just simply remove the -w switch?

tom

5:59 am on Sep 26, 2002 (gmt 0)

10+ Year Member




that did it andreas, thank you for taking the time to help me out :)
12:59 pm on Sep 26, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad I could help Tom.

Just a word of advice: While developing your script use the -w switch. It will be really helpful. Once you tested your scripts and they work ok remove the -w on your production system.

Yet a better way would be to exit your script immediately if there is no valid input and avoid the warnings this way.

Andreas