in reply to Twelve Days of Christmas

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'

Replies are listed 'Best First'.
Re: Re: Twelve Days of Christmas (with help from CPAN)
by TheDamian (Vicar) on Dec 14, 2002 at 04:31 UTC
    Very nice. But still not Lazy enough. ;-)

    Try this:

    use Lingua::EN::Inflect qw/inflect NUM PART_PRES/; use Lingua::Conjunction qw/conjunction/; my @gift = ( '', 'partridge in a pear tree', 'turtle dove', 'French hen', 'calling bi +rd', 'gold ring', 'goose', 'swan', 'maid', 'lady', 'lord', 'piper', 'drummer', ); my @action = map {$_ && PART_PRES $_} ( '', '', '', '', '', '', ' a-lay', ' a-swim', ' a-milk', ' dance', ' a-leap', ' pipe', ' drum', ); for my $day( 1..12 ) { print inflect("On the NUMWORDS(ORD($day)) day of Christmas,\n"), "my true love gave to me:", conjunction( map { NUM($_); inflect "\n\tA(PL_N($gift[$_]))$action[$_]"} reverse 1..$day ), ".\n\n"; }

    Which then makes it easy to change it to:

    use Lingua::EN::Inflect qw/inflect NUM PART_PRES/; use Lingua::Conjunction qw/conjunction/; my @gift = ( '', 'Swiss Army switch statement', 'style of OO', 'loop type', 'sigil fix', 'catch block', 'junction', 'ref', 'sub', 'type', 'try', 'function', 'less-than', ); my @action = map {$_ && PART_PRES $_} ( '', '', '', '', '', '', ' OR', ' a-bind', ' overload', ' a-check', ' a-catch', ' curry', ' chain', ); for my $apo ( 1..12 ) { print inflect("In the NUMWORDS(ORD($apo)) Perl Apocalypse,\n"), "my Larry gave to me:", conjunction( map { NUM($_); inflect "\n\tA(PL_N($gift[$_]))$action[$_]"} reverse 1..$apo ), ".\n\n"; } ;-)
Re: Re: Twelve Days of Christmas (with help from CPAN)
by ibanix (Hermit) on Dec 13, 2002 at 17:10 UTC
    Santa has to leave the Linuga::EN::Inflect module under the tree for your code to work... :-P
    I like it tho! ++!

    ibanix

    $ echo '$0 & $0 &' > foo; chmod a+x foo; foo;