Update: Never mind, there's enough responses here already
As mentioned before, you need to change that loop. Here is my offering:
sub MysqlIN {
# Why is that '@_' in there, are you passing in an
# array of three values?
# That's what I'll assume, so I'll change this line
#my %dateparts = ( YEAR => '', MONTH => '', DAY => '', @_, );
# To this:
my %dateparts = ( YEAR=>shift, MONTH=>shift, DAY=>shift );
my $element;
while (my ($name, $value) = each %dateparts) {
# Number validation added
die "Invalid value for $name" unless $value and $value=~/^\d+$/;
# You don't need to exit, you already died!
# exit;
}
my $mysqldate = join ("-", @dateparts{qw(YEAR MONTH DAY)});
return $mysqldate;
}