Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-01-2012, 06:28 AM   PM User | #1
begood321
New Coder

 
Join Date: Sep 2012
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
begood321 is an unknown quantity at this point
Getting uninitialized value error from timelocal function

Hi guys I can't seem to figure out why my code is complaining below even though I initialize variable:

Use of uninitialized value in subtraction (-) at C:\Temp\users_log2.pl line 225 (#1)

Syntax check is okay. Hence it appears from error I get some correct values but not all.

Here is the block of code where issue occurs:
Code:
# search file one line at a time to locate target string
foreach my $line (@file) {
	$ctr++;

	chomp $line; # remove carriage return line feed

	$line =~ s|.*\s+\w+\s||; # remove all characters prior in target string	
	$line =~ s|\s+$||;	# remove extra spaces at end of line
	
	if ($line =~ m|-0|) { # remove leading 0 from day
		$line =~ s|0||;
	}

	my $teamsite_user_access_date = $line;
	
	# Convert dates and times into seconds since epoch
	my ($mon, $mday, $year) = split(/-/, $teamsite_user_access_date);
	
	my $teamsite_user_access_date_epoch = 0;
	eval {
	  $teamsite_user_access_date_epoch = timelocal(0,0,0,$mday,$mon-1,$year); # set teamsite user access date to numeric value
	};	
	
	# calculate days of teamsite user access
	my $result = ($tod_date_epoch - $teamsite_user_access_date_epoch) / $day_sec;
	
	# ###### print lines with dates >= 90 days ##### 	
	if ($result >= 90)
	{
		print MYFILE "teamsite_user_access >= 90 days: $teamsite_user_access_date\n\n\n";
	}
}
Here is the actual line where the code complains:
Code:
$teamsite_user_access_date_epoch = timelocal(0,0,0,$mday,$mon-1,$year); # set teamsite user access date to numeric value
Just posting problem section for now because entire code is 238 lines. Hope someone can help me here. Thanks

Last edited by begood321; 10-01-2012 at 06:38 AM..
begood321 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:54 AM.


Advertisement
Log in to turn off these ads.