[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Real World Perl



At Wed, 21 Mar 2001 23:34:38 -0800, "Derek J. Balling" <dredd@megacity.org> wrote:
> At 9:57 PM -0800 3/21/01, Vicki Brown wrote:
> >sub GetToday2 {
> >     my (undef,undef,undef,$mday,$mon,$year) = localtime(time);
> >
> >     sprintf("%4d%02d%02d", $year + 1900, $mon+1, $mday);
> >
> >}
> 
> why not do:
> 
> my ($mday,$mon,$year) = (localtime(time))[3..5];

a) It's a nasty, non-standard way of ordering dates.

b) It doesn't pad single digits with preceding zeroes.

Mind you, the original _can_ be improved:

my ($mday, $mon, $year) = (localtime)[3 ..5];
sprintf("%4d%02d%02d", $year + 1900, ++$mon, $mday);

On a similar subject, if you haven't already done so it's _well_ worth
checking out the new Date-MMDDYY module that was recently uploaded to
the CPAN.

Dave...

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe