I've been working on an exercise to generate the English "Twelve days of Christmas song". So far, I've come up with the following:

for(<DATA>){s/%/ing/;$_=($i++?$i-1+print" ":a)." $_";print"On the $i",(st,nd,rd)[$i-1]||th," day of Christmas, my true love gave to me: ",$t=$_.$t}__DATA__ partridge in a pear tree. turtle doves and French hens, call% birds, golden rings, geese a-lay%, swans a-swimm%, maids a-milk%, ladies danc%, lords a-leap%, pipers pip%, drummers drumm%,

That generates the following text:

On the 1st day of Christmas, my true love gave to me: a partridge in a pear tree. On the 2nd day of Christmas, my true love gave to me: 2 turtle doves and a partridge in a pear tree. On the 3rd day of Christmas, my true love gave to me: 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 4th day of Christmas, my true love gave to me: 4 calling birds, 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 5th day of Christmas, my true love gave to me: 5 golden rings, 4 calling birds, 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 6th day of Christmas, my true love gave to me: 6 geese a-laying, 5 golden rings, 4 calling birds, 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 7th day of Christmas, my true love gave to me: 7 swans a-swimming, 6 geese a-laying, 5 golden rings, 4 calling birds, 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 8th day of Christmas, my true love gave to me: 8 maids a-milking, 7 swans a-swimming, 6 geese a-laying, 5 golden rings, 4 calling birds, 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 9th day of Christmas, my true love gave to me: 9 ladies dancing, 8 maids a-milking, 7 swans a-swimming, 6 geese a-laying, 5 golden rings, 4 calling birds, 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 10th day of Christmas, my true love gave to me: 10 lords a-leaping, 9 ladies dancing, 8 maids a-milking, 7 swans a-swimming, 6 geese a-laying, 5 golden rings, 4 calling birds, 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 11th day of Christmas, my true love gave to me: 11 pipers piping, 10 lords a-leaping, 9 ladies dancing, 8 maids a-milking, 7 swans a-swimming, 6 geese a-laying, 5 golden rings, 4 calling birds, 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 12th day of Christmas, my true love gave to me: 12 drummers drumming, 11 pipers piping, 10 lords a-leaping, 9 ladies dancing, 8 maids a-milking, 7 swans a-swimming, 6 geese a-laying, 5 golden rings, 4 calling birds, 3 French hens, 2 turtle doves and a partridge in a pear tree.

My script is 343 bytes, which is better than zip and tar+gzip but worse than gzip:

-rw-r--r-- 1 john john 294 May 1 13:29 12days.gz -rw-r--r-- 1 john john 343 Apr 30 04:00 12days.pl -rw-r--r-- 1 john john 370 May 1 13:30 12days.tar.gz -rw-r--r-- 1 john john 2169 May 1 13:29 12days.txt -rw-r--r-- 1 john john 439 May 1 13:30 12days.zip

Does anybody have a shorter solution? For simplicity's sake, I've limited the challenge to digits rather than written numbers.


In reply to 12 days of Perl? by johnaj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.