Re: Adding a comma to format localtime

[email protected] (Paul Archer)
Newsgroups perl.beginners.cgi
Message-ID <[email protected]>
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];

Paul


11:57am, Susheel Koushik wrote:

> use this:
>
> $str = localtime;
> @fields = split/ /,$str;
> $str2 = "$fields[0]".","." $fields[2]"." $fields[1]"." $fields[4]"."
> $fields[3]";
> print ("$str2\n");
>
> 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
>> 
>>   Best and thanks,
>>   Gregg
>> 
>>  	---------------------------------
>> Looking for earth-friendly autos?
>>  Browse Top Cars by "Green Rating" at Yahoo! Autos' Green Center.
>
> -- 
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>



-------------------------------------------------------------------
Perl elegant? Perl is like your grandfather's garage. Sure, he kept
most of it tidy to please your grandmother but there was always one
corner where you could find the most amazing junk. And some days,
when you were particularly lucky, he'd show you how it worked.
----------Shawn Corey <shawn.corey [at] sympatico.ca>--------------
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.