in reply to Re: date as part of filename
in thread date as part of filename

I can't find anything that says the time components can be negative. Any idea what POSIX (the spec, not the module) says?

Replies are listed 'Best First'.
Re^3: date as part of filename
by wind (Priest) on May 12, 2011 at 23:21 UTC

    Good Question, it's an undocumented feature that I've simply observed others using from time to time.

    However, testing it shows that it works across month boundaries, but fails on year boundaries

    use POSIX qw(strftime); use strict; use warnings; my @date = localtime; while (<DATA>) { my ($year, $mon, $day, $expected) = split; @date[3,4,5] = ($day, $mon, $year); my $fmt = strftime "%Y%m%d", @date; print "$fmt <=> $expected " . ($fmt eq $expected ? 'matched' : 'fa +iled') . "\n"; } =prints 20110501 <=> 20110501 matched 20110430 <=> 20110430 matched 20110429 <=> 20110429 matched 20110102 <=> 20110102 matched 20110101 <=> 20110101 matched 20110512 <=> 20101231 failed 20110512 <=> 20101230 failed =cut __DATA__ 111 4 1 20110501 111 4 0 20110430 111 4 -1 20110429 111 0 2 20110102 111 0 1 20110101 111 0 0 20101231 111 0 -1 20101230

    Truth is, using DateTime is cleaner anyway, so will update my script.

      Thanks for the reply. I wont be able to work with the modules. So would have to use localtime Thanks a lot for your help
        It makes no sense that you can use (malfunctioning) code from PerlMonks but not (functioning) code from CPAN.