use strict;
use warnings;
use DateTime;
use IO::Prompt::Tiny qw( prompt );
# Get a DateTime object for birthday and now based on user input.
my( $bday, $now )
= map { DateTime->new( prompt_date( $_ ) ) } qw( Birth Today's );
die "Birth date must be in the past.\n" unless $bday < $now;
# Perform the math.
print "\nYou are ", $bday->delta_days($now)->in_units('days'), " days old.\n";
# Prompting: pass date entry type, receive a day=>__, month=>__, year=>__ hash.
sub prompt_date {
print shift, " date entry:\n";
return map { $_ => prompt "\tPlease enter $_:" } qw( day month year );
}
####
Birth date entry:
Please enter day: 27
Please enter month: 9
Please enter year: 1954
Today's date entry:
Please enter day: 02
Please enter month: 10
Please enter year: 2013
You are 21555 days old.
####
use strict;
use warnings;
use DateTime;
use IO::Prompt::Tiny qw( prompt );
# Get a DateTime object for birthday and now based on user input.
my( $bday, $now ) = map {
print "$_ date entry:\n";
DateTime->new( map { $_ => prompt "\tPlease enter $_:" } qw(day month year) )
} qw(Birth Today's);
die "Birth date must be in the past.\n" unless $bday < $now;
# Perform the math.
print "\nYou are ", $bday->delta_days($now)->in_units('days'), " days old.\n";