in reply to formatted output of localtime()

Too bad Perl doesn't have the strftime function. If you want something really nice, how about implementing that, or binding to C's version via XS?

I think you could use sprintf with things like %02d instead of the loop to add leading zeros, and instead of concatenating everything together in $tstamp.

Check out Time::localtime. It does what you do on the hash assignment of localtime.

The %months=reverse(%months) bothers me. You're changing it each time the function is called, flipping it back and forth. That seems fishy. But, why not set up the lookup the way you need it in the first place?

—John

Replies are listed 'Best First'.
Re: Re: formatted output of localtime()
by merlyn (Sage) on Sep 18, 2001 at 01:30 UTC
    Too bad Perl doesn't have the strftime function.
    I can't tell if you're joking, or serious. I'll presume you're serious, and post the following code without comment:
    use POSIX qw(strftime); print strftime("Today is %A, %d %B %Y!\n", localtime);
    This has worked for as long as the POSIX module has been around.

    -- Randal L. Schwartz, Perl hacker

      Yes, was serious. Not listed under "time" functions in perlfunc. Other C-like functions such as sprintf don't require special modules. I work on Windows, so am not particulary familiar with the POSIX module. I use the Win32 modules.

      —John

Re: Re: formatted output of localtime()
by japhy (Canon) on Sep 18, 2001 at 01:30 UTC
    Err, POSIX::strftime().

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;