The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by kirkw]

I have been trying to set up a script that takes two times and finds the time
difference between them. In this case I'm looking for day length. The file to
work on looks like this:

"doy","sunrise","sunset"
1,742,1732
2,742,1733
3,742,1734
4,742,1735
5,743,1736
...

where 742 is 7:42 am and 1732 is 5:32 pm. Which module should I use on
this?
import-bot (20211) [Avatar] Offline
#2
Re: finding the time difference
[Originally posted by dave]

> I have been trying to set up a script that takes two times and finds the time
> difference between them. In this case I'm looking for day length. The file to
> work on looks like this:
>
> "doy","sunrise","sunset"
> 1,742,1732
> 2,742,1733
> 3,742,1734
> 4,742,1735
> 5,743,1736
> ...
>
> where 742 is 7:42 am and 1732 is 5:32 pm. Which module should I use on
> this?

This is one of those cases where I think a module would really be overkill.
I'd fo something like this:

while (<DATA>smilie {
my ($n, $s, $e) = split /,/;

my ($s_hr, $s_min) = $s =~ /(d?d)(dd)/;
my ($e_hr, $e_min) = $e =~ /(d?d)(dd)/;

$s = 60 * $s_hr + $s_min;
$e = 60 * $e_hr + $e_min;
my $min = $e - $s;

print "Day 1: $min (", int($min / 60), " hours, ", $min % 60, " mins)
";
}


hth,

Dave...
import-bot (20211) [Avatar] Offline
#3
Re: finding the time difference (Date::Calc)
[Originally posted by ybic]

Not having the munging expertise of the esteemed author, I'd look into the
Date::Calc module. It probably *is* overkill, but less so than Date::Manip.

cheers,
Don