I have a perl script which prints epoch value of date in milliseconds as the output.
My reuirement is that once the output is printed,the day variable shld increment by 1 and when i execute the script for the second time the output shld be for the new day value.
I would like to increment $day value to 15 after first execution of the script.If i understood correctly the solution u gave is to store the result ie output in a file.
How to increment $day=14 to $day=15 ?
my $somefile = "/tmp/whatever" ;
sub store {
my $what = shift ;
open my $file , ">$somefile" or die "$!" ;
print $file "$what" ;
close $file;
}
sub read_it {
open my $file , "<$somefile" or die "$!" ;
my $result = <$file> ;
close $file ;
return $result ;
}
if ( -f $somefile ) {
my $result = read_it();
$result += 24 * 3600 ; # increment 1 day , date should be in epoch format
store($result);
# do whatever you want with new result
} else {
# original code
#
store($starting_date);
}
Store data in file in epoch format .
There is almost no exception handling in this code and it will not work concurrent .
Thanks for the reply but this does not give me what is required.I hope my query was clear.
when i execute the code which i posted it prints me the epoch value for "Aug 14 00:01:00".
Once it has printed the output,i want that the day value is inremented by 1 ie "Aug 15 00:01:00" so that i can get the epoch value of Aug 15 when i execute the script the second time.
#!/usr/bin/perl
use Time::Local ;
$sec=00;
$min=01;
$hours=00;
$day=&get_day;
$month=7;
$year=109;
$Beg_time = (timelocal($sec,$min,$hours,$day,$month,$year) * 1000);
print "Epoch Beg Value: $Beg_time\n";
add_day();
sub get_day {
my $val = 0;
open (F,"file") || die "unable to open";
while ($line = <F>){ chomp($line);if ( $.==1) { $val=$line }};
close F;
return $val;
}
sub add_day {
my $cday = 0;
$cday = &get_day;
$cday=$cday+1;
open (F,">file") || die "unable to open";
print F "$cday\n";
close F;
}
this will take the day value from a file called "file".