Hi All,I am writing a perl script in which I need to get duration passed between two system time instances.example: Lets take two system time:Time 1: Sun Jun 3 01:24:09 2007Time 2: Thu Jun 7 09:17:52 2007Now how do I get time diference between these two instances in terms of number of days.I have checked packages under the perl\lib directory such as DateTime.pm and Duration.pm file but could not figure out how to do so.Please guide me people.
You have to change the datetime format in a epoch format, so that those can be manipulated.
Unfortunately both these versions lacks packages: Date::Manip, Time::Interval, Time::Zone package. So i culd not use methods supported by these packages.
Hi Sailesh,I have downloaded latest perl version as i had already mentioned but could not get the above mentioned packages in it.
% cpan[color=brown]...cpan> install Date::Manip...cpan> quit%[/color]
Thanks a lot people for responding.I really acknowledge your efforts.My problem still remains the same.Perl Version: previously we were using version 5.6.1 built for MSWin32-x86-muti-thread.Yesterday i installed another perl version from ActiveState.com: version 5.8.8 built for MSWin32-x86-muti-thread.Unfortunately both these versions lacks packages: Date::Manip, Time::Interval, Time::Zone package. So i culd not use methods supported by these packages.I have even gone through these useful files: DateTime.pm, Date.pm, Duration.pm but could not figure out how to get time interval passed between two system times in terms of days.Friends if you get some time then please do similar time interval calculation at your end then tell me how to do so.Please tell me which version of perl you use.Also please send me the required packages or files or rather tell me where from can i download a perl version which has entire list of packages supported by perl.-Thanks again everyone Retesh
[...]Now I face problem in deleting log files.I am writing in my code: unlink($file);$file represents file path. eg:$file="G:\tmp\wft_generate_teamsite_1811"but the log files dosent get deleted doing this. Please tell me the way to get around this. The way to delete a single file from a folder.I know we could use delete command to remove a list of files. but how to do what i intend to execute??Depending on you guys again.-Thanks Retesh
...my $file = "G:\tmp\wft_generate_teamsite_1811";unlink($file);...
[...]Actual Problem: when i retrieve each log file from a list of log files and then unlink it then it doesnt get deleted.I have written a perl script to get list of all log files within a folder then only those files gets deleted who fall under a certain condition.I try to explain this by writing few portion of the code:#####################################################@lockCmd represent list of all log files inside a folderforeach $brtmp(@lockCmd) { chomp($brtmp); my $fl = $brtmp; print FILE "\nFile in log folder : $fl\n"; &checkFile($fl);}####Sub routine to delete only those files which falls under the specied condition####sub checkFile(){my $log = shift;if (condition fulfilled) {my $dl = $log;$dl =~ s/\\/\\\\/g;print FILE "\nDeleting $dl\n";if (unlink($dl) == 0) { print FILE "File deleted successfully.";} else { print FILE "File was not deleted.";} } }####################################################Now output of this code is:-------------------------------------------------------------------------- Deleting G:\\tmp\\wft_generate_teamsite_1853.log File deleted successfully. --------------------------------------------------------------------------But the log file represented by $dl still exsist in its folder.I am clueless people. Please suggest me something.
if (unlink($dl) != 0) { print FILE "File $dl deleted successfully.";} else { print FILE "File $dl was not deleted. ($!)";}
unlink($dl) || warn("File $dl was not deleted ($!)\n");
so as of now my problem has been resolved but the logical question remains unanswered. Why this didnt worked: (unlink($dl);
It's not so much a *logical* question as simply bugs in your code. Command $dl =~ s/\\/\\\\/g; creates an invalid Path, subsequent unlink returns the number of files successfully deleted ( in your case, zero ) and you triumphantly print "File deleted successfully".
... =~ s/\\/\/\//g;
... =~ tr|\\|/|;