in reply to localtime()

if (length $mday == 1){ $mday = "0".$mday; }
Can we please put an end to this idiom now? I think I first saw it in a MSA program, and now am boggled at how far it has gotten. Definitely a bad book or website you got that from, sir. I'd distrust the rest of the stuff you got there.

As for "yesterday", just subtract 86400 from "time", and do localtime() on that. It'll be wrong (by an hour) twice a year, but close enough for most purposes.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: localtime()
by Belgarion (Chaplain) on Jul 16, 2004 at 20:24 UTC

    I always found that expression odd. I usually use:

    $mday = sprintf "%02d", $mday;

    If the $mday variable is already a two digit value, no harm, and if not it now is one. Less code is nice.

Re^2: localtime()
by Nkuvu (Priest) on Jul 16, 2004 at 20:27 UTC
    I personally use the strftime approach that blokhead shows, but I'm curious. Why do you dislike this idiom? Is it due to the length checking? The use of a two digit day? The fact that this can be done easily with sprintf? Or just the fact that the entire date format can be done more easily through strftime?