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:
# 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:
$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.