Programming
A lot of times in Unix, you would want to find out how many seconds (or minutes, or hours) back a particular file was updated. You would want to do it for several reasons - find out the last time some configuration file was changed, or may to track some update done by a different system, or anything that fancies your mind.
Though the script can be written as a Unix shell script, I found it a bit cumbersome. Moreover, the PERL solution was much more flexible, elegant and readable.
So, here is the PERL script that calculates the time period between the modified date of a file, and the system date.
#!/usr/bin/env perl use File::stat; # Declare variables my $filename; my $FILE_HANDLE; my $file_stat; my $current_time; my $diff_seconds; $filename = '/path/of/file/filename.ext'; # Open the file open ($FILE_HANDLE, $filename) or die "Can't open $filename!"; # Get the file status structure $file_stat = stat($FILE_HANDLE); # Get the current time $current_time = time; # Get the elapsed time in seconds $diff_seconds = time - $file_stat->mtime; # Do whatever you want with the $diff_seconds print "\n$filename was modified $diff_seconds seconds back.\n"; # All done
Note:
- Instead of the $file_stat->mtime, you can use $file_stat->ctime to get the time from creation of the file.
- To get the elapsed time in minutes, divide $diff_seconds by 60. For hours, divide by 3600. And so on.
Ever since I became officially invovled in Drupal, the importance of version control system seems to grow larger in my point of view. The ease of use in coding over a duration, and working on multiple projects, with multiple people, are all the advantages of using a version control.
CVS is just one of the systems used for version control. There are others like SVN.
My day job invovles development, and that too in a team of other developers with mutliple projects that share code between each other. The present version control system (or seeming lack of it) leaves a lot to be desired. The difference in working on my 'bread earning' projects and Drupal project is like day and night.
I am pushing for the use of CVS (or any version control as a matter of fact) in my workplace. But as in all corporate settings, things move pretty slowly. There are a lot of hoops to jump through.
It took me quite a while to get back on the Drupal contributor track after my hibernation in my other projects. Yesterday, I could chip in some time on it and get the views integration enabled for the Webcomic module. The updated has been done to both the HEAD and the 5.x-1.x-dev branches.
Its performance is a bit spotty and it requires a bit of bug fixing. So, if you are intending on using the Webcomic module on your Drupal installation, go ahead and download the latest development release, and report a bug.