Re: Adding a comma to format localtime

[email protected] (Peter Scott)
Newsgroups perl.beginners.cgi
Organization Pacific Systems Design Technologies
Message-ID <[email protected]>
On Thu, 12 Apr 2007 05:56:14 -0500, Paul Archer wrote:
> A cleaner way to do it is:
> printf "%s, %s %s %s %s\n", (split ' ', localtime)[0,2,1,4,3];
> Or, if you want to save it to a variable:
> my $dateout = sprintf "%s, %s %s %s %s\n", (split ' ', localtime)[0,2,1,4,3];
>>
>> On 4/9/07, Gregg O'Donnell <[email protected]> wrote:
>>> All,
>>>   I use this line of code:
>>>   my $datetime = join ' ', (split ' ', localtime)[0,2,1,4,3];
>>> 
>>>   To create this result:
>>>   Mon 9 Apr 2007 09:15:05
>>> 
>>>   How can I add a comma to this result to get:
>>>   Mon, 9 Apr 2007 09:15:05

Personally, I find this more maintainable and readable:

use POSIX qw(strftime);
my $datetime = strftime "%a, %d %b %Y %T", localtime;

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.