Hi guys I am very new to perl and programming in general. I have a question about getting the amount of days between two dates. I do not want to use any modules- (just A LOT of code). Here is my code so far any advice for me.? I cant get my head around trying to get the right number of days in different years- as you will see in the code

#!/usr/bin/perl use strict; use warnings; print "please enter day of birth: "; my $d = <STDIN>; print "please enter month of birth: "; my $m = <STDIN>; print "please enter year of birth: "; my $y = <STDIN>; chomp($d, $m,$y);#strip newlines print "please enter current day: "; my $cd = <STDIN>; print "please enter current month: "; my $cm = <STDIN>; print "please enter current year: "; my $cy = <STDIN>; chomp($cd, $cm,$cy); my$days=0; if ($y>$cy){ warn "Birth Year Cannot be after the current year."; } elsif ($y==$cy){ $days= $days + NumberOfDaysBetween($d,$cd ,$m,$cm ); print "$days"; } else { my$years= ($cy-$y) * 365; $days= $days + NumberOfDaysBetween($d,31,$m,12) + NumberOfDaysBetween( +1,$cd,1,$cm) + $years; print "war war$days"; } sub NumberOfDaysBetween { my$daysBetween; my$startDay=shift; my$endDay=shift; my$sMon=shift; my$eMon=shift; if ($y <= $cy){ if ($sMon > $eMon || $sMon == $eMon&& $startDay > $endDay){ print "invalid input"; } elsif ($sMon == $eMon && $startDay<= $endDay){ $daysBetween = $endDay- $startDay; } else { $daysBetween =((&NumberOfDaysInMonth($sMon))-($startDay-1)) + +$endDay + &cumulativeDaysInMonths($sMon,$eMon); } } return $daysBetween; } sub NumberOfDaysInMonth { my $mon=shift; my$numOfDaysInMonth; if ($mon == 2) { $numOfDaysInMonth = 28; } elsif ($mon == 9|| $mon == 4|| $mon == 6|| $mon == 11) { $numOfDaysInMonth = 30; } else { $numOfDaysInMonth = 31; } return $numOfDaysInMonth; } sub cumulativeDaysInMonths { my $sMonth=shift; my $eMonth=shift; my$daysRange=0; $eMonth--; while ($eMonth>$sMonth){ $daysRange=$daysRange + NumberOfDaysInMonth($eMonth); $eMonth-- } return$daysRange; }

In reply to perl basic count days between two dates by scripter87

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.