Archive for June, 2003

Jun
21

Create Dir Path

Posted by: celso | Comments (0)

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.

Categories : Perl
Comments (0)
Jun
19

Creating Timestamp

Posted by: celso | Comments (0)

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;
}
Categories : Perl
Comments (0)

Gallery