in reply to Finding time difference from two strings
That's just a very crude demonstration, but it gives you an idea what needs to be done.use Time::Local; my $beginning = 'Thu Oct 24 17:37:58 2007'; my $end = 'Fri Oct 26 06:54:09 2007'; my %month = ( Jan => 0, Feb => 1, Mar => 2, Apr => 3, May => 4, Jun => 5, Jul => 6, Aug => 7, Sep => 8, Oct => 9, Nov => 10, Dec => 11 ); for ( $beginning, $end ) { my ( $mo, $dy, $hr, $mi, $se, $yr ) = ( split /[\s:]/ )[1..6]; $mo = $month{$mo}; $_ = timelocal( $se, $mi, $hr, $dy, $mo, $yr ); } printf "%d sec elapsed\n", $end - $beginning;
update: here's a more perlish way to initialize month numbers:
my $i=0; my %month = map {$_=>$i++} qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct +Nov Dec/;
|
|---|