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 ); }