Hi Experts,
Here i am trying to create a script for Auto Back up script to Back up files. files are taking a back up with help of archive zip module along with mentioned the date in corresponding Folder name. Here i am create one xml file for daily updation. BAsed on the date script will be executed at once. which not equal to current date. else back up does not pick bcs same condition which is equal to true. XML file does not get append the daily date.

use strict;
#use File::Copy;
use Archive::Zip;

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
$year += 1900;
$mon++;
my $today =  "$mon-$mday-$year";
print $hour-$min;
my $filetobecopied = "test.pl";
my $newfile = "test1.pl";mkdir($today);
mkdir($today);

my $zip = Archive::Zip->new();
$zip->writeToFileNamed("$today/$newfile\.zip"); 


open (WRK, "logfile.xml") || die "Cannot open the input file";
read WRK, my $wrk_xml, -s WRK;
close(WRK);

my $getdate=$1 if ($wrk_xml=~ m{<date>(.*?)</date>});
print $getdate;

my $date_flag;
if($getdate == $today){ $date_flag = 'false';}
else {
    
    $date_flag = 'true';}
 
if($date_flag == 'true'){
print "test";
    
### Prepare ready.xml process . . .
my $ready=<<READY;
<backup-file>
<date>$today</date>
<name>$newfile</name>
</backup-file>

READY
print "test";
open (REA, ">>logfile\.xml") || die "Cannot Open thelog xml file";
print REA $ready; 
close (REA);
}
else
{
print "$hour- $min";    
my $ready=<<READY;
<backup-file>
<date>$today $hour-$min</date>
<name>$newfile</name>
</backup-file>
READY

open (REA, ">>logfile\.xml") || die "Cannot Open thelog xml file";
print REA $ready; 
close (REA);    
}


Advance Thanks,
Senthil. V

my $today = "$mon-$mday-$year"; , Here $today holds the string values only.
But you are using ( if($getdate == $today), if($date_flag == 'true') ) numerical comparision opertor.

When you want to compare two string use the 'eq' operator.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.