Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: perl basic count days between two dates

by scripter87 (Novice)
on Oct 03, 2013 at 12:34 UTC ( [id://1056757]=note: print w/replies, xml ) Need Help??


in reply to Re^3: perl basic count days between two dates
in thread perl basic count days between two dates

ok using the debug method you have shown my numberofdays sub seem to be out by 1. e.g print "1,1,1,1 == " = O- which is ok. print "1,1,5,1 == " = 0 because the format of the sub is d,cd,m,cm: so when I changed it to 1,1,1,5 it printed 121- which is ok. Now here is where it got weird. "1,1,1,2 == 32 (should be 31) again print "8,3,3,8 == 149 (should be 148). How is it possible to be half correct??

  • Comment on Re^4: perl basic count days between two dates

Replies are listed 'Best First'.
Re^5: perl basic count days between two dates
by SuicideJunkie (Vicar) on Oct 03, 2013 at 14:13 UTC

    This is where you should follow the flow of the subroutine with those print statements. Follow along with the math and see where your answer differs from what it should be. Look particularly closely at points where something new changes (such as the first/last day of a month)

Re^5: perl basic count days between two dates
by jethro (Monsignor) on Oct 04, 2013 at 13:31 UTC

    What SuicideJunkie said. Either the logic in NumberOfDaysBetween is wrong or you have to test the subroutines in there (NumberOfDaysInMonth and cumulativeDaysInMonths) similar to NumberOfDaysBetween. If one or both of them produce wrong results then plaster them with print statements until you know what is going on.

    PS: Looked at your code again and subroutines are difficult to see because there isn't even one empty line separating them. Programs are easier to read for humans when structure can be seen at a glance. I even tend to separate subs with lines like "#----------------------" additionally to a few empty lines.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1056757]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-24 03:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found