Welcome to WebmasterWorld Guest from 54.196.244.186

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)

New User

10+ Year Member

joined:Sept 21, 2002
posts:7
votes: 0


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 Sept 25, 2002 (gmt 0)

Administrator

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

joined:July 24, 2001
posts:15755
votes: 0


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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


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 Sept 25, 2002 (gmt 0)

New User

10+ Year Member

joined:Sept 21, 2002
posts:7
votes: 0


Thanks andreas.

so I just simply remove the -w switch?

tom

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

New User

10+ Year Member

joined:Sept 21, 2002
posts:7
votes: 0



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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


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