in reply to Hash Math

What have you tried? What worked? What didn't? See How do I post a question effectively?.

First, I would suggest using ISO_8601 as your date format, since this sorts easily. For the date arithmetic, I would suggest using a module to do the math, since dealing with days-of-month variation is an unnecessary headache. DateTime is a common choice for that. You could implement the looping component using two nested loops, a la:

for my $time1 (sort keys %hash) { for my $time2 (sort keys %hash) { next if $time2 < $time1; ... # And do the math } }

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^2: Hash Math
by marlowvoltron (Novice) on Jun 09, 2014 at 20:59 UTC

    When I try your code, I get this Can't modify subtraction (-) in scalar assignment

      There is no subtraction in my posted code. What code did you run? My best guess is that you've forgotten some quoting around your dates.

      Note that if you are using ISO 8601 w/ hyphens, the numerical comparison (the next if... bit) will break down, and so you'll need to use DateTime's built-in comparator.


      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.