I'm pretty new to Perl but I assumed I had in mind basics like variables definition and scope... but it seems not. My problem is that I keep on bumping into error:
Global symbol "$save_from_date" requires explicit package name at myMover.pl line 40
I've got a function in which I intend to compare a file date versus another date (default or argument), but it's failing.
Here is the troublesome code, extract:
# Process source directory
sub ParseSource {
my $file = $_;
my $filedate = localtime( ( stat $file )[9] )->ymd('');
if ( $filedate >= $save_from_date ) {
print "[To Archive] $file";
}
}
# Default Values
my $source_directory = 'C:\Users\Public\Documents';
my $destination_directory = 'C:\Users\Public\Documents\Archive';
my $save_from_date = strftime "%Y%m%d", localtime;
my ( $verboseornotverbose, $display_help ) = undef;
GetOptions(
"verbose!" => \$verboseornotverbose,
"help|h!" => \$display_help,
"source_dir|s:s" => \$source_directory,
"destination_dir|d:s" => \$destination_directory,
"date|t:i" => \$save_from_date
);
usage() if $display_help;
# Basic checks
unless ( -d $source_directory ) { die "ERROR -- Source directory [$source_directory] does not exists" }
unless ( -d $destination_directory ) {
unless ( mkdir $destination_directory ) {
die "ERROR -- Destination directory $destination_directory does not exists and couldn't be created'";
}
}
unless ( $save_from_date <= strftime "%Y%m%d", localtime ) {
die "ERROR -- Wrong or unknown date format [$save_from_date] should be before or equal today\'s' date'";
}
print $save_from_date ;
# Here we parse the source directory
find( \&parseSource, $source_directory );
This is the comparison that is failing:
if ($filedate >= $save_from_date)
Could you please explain me what I missed in that sub ?
I've read many other posts and some variables definition tutorials but I couldn't get the clue of my problem...
Thank you !