I'm trying to find the difference in seconds between two dates. The two (and only two) dates come as standard out like:
Sun 09 30 06 42 36 2007
Tue 10 02 06 01 55 2007
(Note: the months correspond to September and October respectively.)
I tried to do this with awk because I use awk in plenty of other places but awk's mktime() is a GNU-only addition it seems and I only have access to barebones Solaris installs. The only alternative remaining I think is Perl's timelocal function in Time::Local which I believe is a part of the standard install, right? My goal is to put a Perl one-liner in a sh script and this is the last piece in the pipe. I've already written a Perl script which works but purely as an exercise for the monkish community, where are the improvements I'm missing?
Here's what I have currently but I am actively working on it though:
my @array;
while (<>) {
chomp;
my @fields = split;
shift @fields;
unshift(@fields, pop(@fields));
$fields[1]--; # decrement the month, timelocal is zero-based
push (@array, timelocal (reverse @fields));
}
print $array[1] - $array[0];
"The three principal virtues of a programmer are Laziness, Impatience, and Hubris. See the Camel Book for why." -- `man perl`