Quantcast
Viewing all articles
Browse latest Browse all 12

POSIX date format in Perl

To make a Perl script portable is to avoid using system commands as much as possible. To deal with date formats actions, you’d better use DateTime or Date::Calc modules.

For a simple formatting of the current date using localtime() Perl function :

#!/usr/bin/perl
use POSIX qw(strftime);
my $date = strftime “%d-%m-%y”, localtime;

Instead of :

my $date = qx(date +%d-%m-%y);

Both work. The first one is more Perlish ;-)

More info :
POSIX Function strftime() in Perl
DateTime Perl module
Date::Calc Perl module


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 12

Trending Articles