I was today tasked with produceing code which took a date in the format CCYYMMDD, printing out a message if it was not the last day of a month. For the real job I used a well notated sub routine but wondered how short I could make a stand alone program. With a little help from the vaults of The Monks, the leap year bit(
I used the Date::leapyear module), I came up with this
my ($y, $m, $d) = (substr($ARGV[0],0,4),substr($ARGV[0],4,2),substr($A
+RGV[0],6,2));
my $ld = (31,28,31,30,31,30,31,31,30,31,30,31)[$m-1];
if (($m-1) == 1){$ld++ if(!($y%100) && !($y%400))||(($y % 100)&&!($y%4
+))}
print "$ARGV[0] is NOT a month end day\n" unless $d eq $ld;
I'm sure that some of the Monks, Saints and Gods around the monestery could make this look like War & Peace but it gave a warm feeling of satisfaction.
I'd also like to thank everyone in the monestery for there continuing help
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.