It's definately something custom, but wouldn't be that hard. Something like:
Code:
#!/usr/local/bin/perl
require "/path/to/default.cfg";
my $start = 1; # Start date position in db.
my $end = 2; # End date position in db.
open (DB, $db_file_name) or die "Nope: $!";
while (<DB> ) {
next if /^\s*$/;
next if /^#/;
chomp;
@data = split (/\|/, $_, $#db_cols);
$diff = &date_to_unix ($end) - &date_to_unix($start);
$total = $diff + $total;
$count++;
}
close DB;
print "Average: ";
print $total / $count;
print "\n";
sub date_to_unix {
# --------------------------------------------------------
# This routine must take your date format and return the time a la UNIX time().
# Some things to be careful about..
# int your values just in case to remove spaces, etc.
# catch the fatal error timelocal will generate if you have a bad date..
# don't forget that the month is indexed from 0!
#
my ($date) = shift;
my ($i, $time) = 0;
my %months = qw!Jan 0 Feb 1 Mar 2 Apr 3 May 4 Jun 5 Jul 6 Aug 7 Sep 8 Oct 9 Nov 10 Dec 11!;
my ($day, $mon, $year) = split(/-/, $date);
($day and $mon and $year and exists $months{$mon}) or die "Can't convert date: $date";
eval {
use Time::Local;
$day = int($day); $year = int($year) - 1900;
$time = timelocal(0,0,0,$day, $months{$mon}, $year);
};
$@ ? die "Can't convert date: $date. Err: $@" : return $time;
}
It's untested but hopefully should give you a start.
Cheers,
Alex