A random note. Barring specific functions to do it for you,
I like constructing yyyymmdd format through a numerical
operation, not a
sprintf.
# Takes the time in seconds as an optional argument.
# Returns the local date in yyyymmdd format.
sub local_yyyymmdd {
my $time = shift || time();
my ($year, $month, $mday) = (localtime($time))[5,4,3];
return 10_000*($year + 1900) + 100*($month + 1) + $mday;
}
Why? Because I have met many languages without a
sprintf, but none without arithmetic. And sure, it may
be ugly, but that is why Larry gave us functions...