I don't understand this problem. This script is meant to read a text file from a content filter and let you query it by any text input. For some reason, it won't return the right date modified date in the section where I ask it to call for it. I want to use that as part of the filename when it saves the output.
It creates the file with no problem, but with it returning the wrong time, it's not helping. When I separated the code that creates the filename, it worked fine. Here's that code:
What am I doing wrong?
Code:
use warnings;
my $TheDB ;
my $Theline ;
my $SuccessCount = 0 ;
print "Type input filename: ";
$TheDB = <STDIN>;
chomp($TheDB);
# Open the database file but quit if it doesn't exist
open(INDB, $TheDB) or die "The database $TheDB could " .
"not be found.\n";
#Creates a list called Ops and stores the stat function ran on the previous input. $Stats runs the date modified option on Ops
$Ops = stat($TheDB);
@Stats = $Ops[9];
#Converts the date to a readable format
($min,$hour,$mday,$mon,$year) = localtime(@Stats);
$RMonth = $mon + 1; #Adds one to month to obtain the correct month
$SYear = ($year % 100); #Runs modulo arithmetic on the year to get the correct short year
@DateMod = ($RMonth, $mday, $SYear, $hour, $min);
#Stores the value of Ops, converted into a readable format, into the variable $Stuff
$Filename = sprintf("%02d%02d%02d%02d%02d", @DateMod);
#Creates a new file named after the contents of $Filename with ".txt" appended
open(OUTDB, ">d:\\"."hits"."$Filename".".txt") or die "File $Filename did not save successfully.";
print "\nType in search string: ";
$dosearch = <> ;
chomp($dosearch) ;
print "\n " ;
while(<INDB>) { # Loop forever
$Theline = $_;
chomp($Theline) ;
if($Theline =~m/$dosearch/i) {
$SuccessCount = $SuccessCount + 1 ;
print ("$Theline \n ");
print OUTDB ("$Theline \n " );
} # End of if
} # End of while(<INDB>)
print "\nProgram finished.\n $SuccessCount Records Found\n\n";
print "Output saved.\n";
print "$Filename"." was the filename used"
It creates the file with no problem, but with it returning the wrong time, it's not helping. When I separated the code that creates the filename, it worked fine. Here's that code:
Code:
#Asks you which file you want to see stats on and seeks your input
print "Which file would you like to see statistics on? [dir:\\path\\filename] ";
$MyFile = <STDIN>;
chomp($MyFile);
#Creates a list called Ops and stores the stat function ran on the previous
#input. $Stats runs the date modified option on Ops.
@Ops = stat($MyFile);
$Stats = @Ops[9];
#Converts the date to a readable format
($Second, $Minute, $Hour, $DayofMonth, $Month, $Year) = localtime($Stats);
$RMonth = $Month + 1; #Adds one to month to obtain the correct month
$SYear = ($Year % 100); #Runs modulo arithmetic on the year to get the correct short year
#Stores the value of Ops, converted into a readable format, into the variable $Stuff
$Stuff = sprintf("%02d%02d%02d%02d%02d", $RMonth, $DayofMonth, $SYear, $Hour, $Minute);
#Creates a new file named after the contents of $Stuff with ".txt" appended
open(TESTING, ">d:\\"."hits"."$Stuff".".txt") or die "Didn't work buddy. Sorry.";
print TESTING "Words"x25;
print "Don't worry, it's saved.\n";
print "$Stuff was the filename used.";
What am I doing wrong?