Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 07:38 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •