Newsgroups: comp.lang.perl.misc
From: m...@op.net (Mark-Jason Dominus)
Date: 1998/05/21
Subject: Re: Idle thoughts...Can I make this leap year function more elegant/efficient?
In article <356749eb.14708...@cnews.newsguy.com>, trying to compact it. If you're trying to speed it up, maybe memoization is a better option. Still, if you want something cute, how about: sub is_leap { Maybe it bothers you that you alsways do three divisions. In that sub is_leap { Or maybe I would never use ``!(X%Y)''. It's hard to understand. !( $year%4 || ($year%100==0) && $year%400 ) Reversing the sense of the test might (or might not) make it more sub regular_year { There's always the fighting-without-fighting approach: %is_leap = map {($_ => 1)} (1201 .. 2399); sub is_leap { You know, this whole exercise seems like a waste of time. Who cares Maybe this is a good opportunity to point out that the point of leap sub is_leap { $_[0] % 33 % 4 == 0 } Now is the perfect time to institute this change. The switchover will You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||