Here is a silly little script that will tell you your unbirthday when run.
#!/usr/bin/perl use strict; use warnings; use Date::Calc qw(:all); use Lingua::EN::Inflect qw(ORD); local $\ = "\n"; sub commify { local $_ = shift; 1 while s/^([-+]?\d+)(\d{3})/$1,$2/; return $_; } print "What year were you born?"; my $birth_year = <>; print "What month were you born?"; my $birth_month = <>; print "What day were you born?"; my $birth_day = <>; my $year = (localtime)[5] + 1900; my $month = (localtime)[4] + 1; my $day = (localtime)[3]; chomp($birth_year,$birth_month,$birth_day); my @birth = ($birth_year,$birth_month,$birth_day); my @today = ($year,$month,$day); # Just figuring how many birthdays you have had. my $birthdays; if ($birth_month > $month) { $birthdays = $year - $birth_year - 1; } else { if ($birth_day > $day) { $birthdays = $year - $birth_year - 1; } else { $birthdays = $year - $birth_year; } } my $days_alive = Delta_Days(@birth,@today); my $unbirthdays = ORD(commify($days_alive - $birthdays)); print "Happy $unbirthdays unbirthday!";
Have a cookie and a very nice day!
Lady Aleena
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Happy unbirthday! (To all, with a challenge)
by ww (Archbishop) on Sep 25, 2011 at 05:24 UTC | |
by Lady_Aleena (Priest) on Sep 27, 2011 at 06:07 UTC | |
by Not_a_Number (Prior) on Sep 27, 2011 at 12:03 UTC | |
by Tux (Canon) on Sep 27, 2011 at 07:45 UTC | |
by Lady_Aleena (Priest) on Sep 27, 2011 at 09:04 UTC | |
Re: Happy unbirthday!
by CountZero (Bishop) on Sep 24, 2011 at 13:33 UTC |
Back to
Cool Uses for Perl