Create Dir Path
June 21, 2003
To create a directory path programatically:
use File::Path; mkpath "/usr/local/apache/htdocs/articles/2003";
This will create the 2003 directory and all parent directories as needed. This is the same as mkdir -p command.
Creating Timestamp
June 19, 2003
Several times I needed a timestamp for whatever reason. Here’s one that will return a scalar containing the current timestamp as in 03Jun19-114251.
sub create_timestamp { my ($sec, $min, $hour, $mday, $mon, $year) = localtime; my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon]; $year %= 100; my $timestamp = sprintf(”%02d%s%02d-%02d%02d%02d”, $year, $month, $mday, $hour, $min, $sec); return $timestamp; }