homepage Welcome to WebmasterWorld Guest from 54.145.252.85
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
errors in cgi script run by cron
1host

10+ Year Member



 
Msg#: 1449 posted 11:22 pm on Sep 21, 2002 (gmt 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.

 

jatar_k

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



 
Msg#: 1449 posted 4:22 pm on Sep 25, 2002 (gmt 0)

any of you perl folk want to take a stab at this?

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1449 posted 6:00 pm on Sep 25, 2002 (gmt 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

1host

10+ Year Member



 
Msg#: 1449 posted 11:52 pm on Sep 25, 2002 (gmt 0)

Thanks andreas.

so I just simply remove the -w switch?

tom

1host

10+ Year Member



 
Msg#: 1449 posted 5:59 am on Sep 26, 2002 (gmt 0)


that did it andreas, thank you for taking the time to help me out :)

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1449 posted 12:59 pm on Sep 26, 2002 (gmt 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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved