www.webdeveloper.com
Results 1 to 2 of 2

Thread: Getting uninitialized value error from timelocal function

Hybrid View

  1. #1
    Join Date
    Sep 2012
    Posts
    17

    Unhappy 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.

  2. #2
    Join Date
    Oct 2007
    Location
    Vienna, Austria
    Posts
    391
    To me, it looks like your first regexp substitution wipes out the whole content of $line. But it's hard to tell without knowing what's in the @file array.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles