Re: Time::localtime help
printf(The current date is %04d-%02d-%02d\n, $now-year+1900, ($now-mon)+1, $ now-mday); It outputs the date in such a format: The current date is 2005-05-16. I would like the name of the month(ex. 'May') displayed instead of 05. What is the easiest way to do this? The most most easiest is to create your own dictionary: my %month = ( 0 = 'Jan', 1 = 'Feb', 2 = 'Mar', 11 = 'Dec', ); and then access it from $month{$now-mon} Peter -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Time::localtime help
Matt Kopeck mailto:[EMAIL PROTECTED] wrote: : use strict; : : use Time::localtime; : my $now = localtime; : : printf(The current date is %04d-%02d-%02d\n, $now-year+1900, : ($now-mon)+1, $ : now-mday); : : It outputs the date in such a format: The current date is : 2005-05-16. I would like the name of the month(ex. 'May') displayed : instead of 05. : : What is the easiest way to do this? A lot depends are you definition of easy. I am familiar with the formats used in the POSIX stringify time function which expects the built-in version of localtime(). This makes it easy for me to use strftime(). YMMV. use strict; use warnings; use POSIX 'strftime'; print strftime The current date is %Y-%b-%d, localtime(); __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Time::localtime help
Matt Kopeck wrote: Hi, Hello, I have the following code: use strict; use Time::localtime; my $now = localtime; printf(The current date is %04d-%02d-%02d\n, $now-year+1900, ($now-mon)+1, $ now-mday); It outputs the date in such a format: The current date is 2005-05-16. I would like the name of the month(ex. 'May') displayed instead of 05. What is the easiest way to do this? The easiest way is to use localtime() in scalar context. $ perl -le' my $now = localtime; print $now; ' Mon May 16 12:31:07 2005 $ perl -le' printf The current date is %04d-%s-%02d\n, ( localtime =~ /(\w{3})\s+(\d+)\s+[\d:]{8}\s+(\d{4})/ )[ 2, 0, 1 ]; ' The current date is 2005-May-16 John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response