Heh, cute. Of course, I couldn't help but simplify this, with a little help from CPAN.
#! /usr/bin/perl -w
use strict;
use Lingua::EN::Inflect qw/NUMWORDS ORD/;
my @gift = (
'this element purposely left blank',
'partridge in a pear tree',
'turtle doves',
'French hens',
'calling birds',
'golden rings',
'geese a-laying',
'swans a-swimmings',
'maids a-milkings',
'ladies dancing',
'lords a-leaping',
'pipers piping',
'drummers drumming',
);
for my $day( 1..12 ) {
print "On the ${\NUMWORDS(ORD($day))} day of Christmas,\nmy true l
+ove gave to me,\n";
if( $day > 1 ) {
print "${\NUMWORDS($_)} $gift[$_],\n" for reverse 2..$day;
print 'and ';
}
print "a $gift[1].\n\n";
}
Of course all those plurals are just begging for Lingua::EN::Inflect::PL but I leave that an exercise to the reader...
Season's greetings to all the monks :o)
print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.