in reply to Re^2: Is this logic correct? Maybe can be rewritten better?
in thread Is this logic correct? Maybe can be rewritten better?

Don't roll your own localtime-to-string routine. Use POSIX and strftime, which aside from requiring no extraneous months array and being less code will also respect the date formatting conventions of the current locate.

Replies are listed 'Best First'.
Re^4: Is this logic correct? Maybe can be rewritten better?
by Nik (Initiate) on Apr 29, 2005 at 16:43 UTC
    So how can i write the following lines iwth the use of strptime:
    my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', +'Sep', 'Oct', 'Nov', 'Dec'); my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = loc +altime; my $date = "$mday $months[$mon], $hour:$min";
    I didnt understand cpans explanation on this.

      See your OS' documentation, as it'll have all the escape codes (man 3 strftime or some variation thereon should find it). In this particular case you probably want strftime( "%d %b, %H:%M", localtime ).