Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

12 Days of Christmas

by zentara (Archbishop)
on Dec 14, 2005 at 13:43 UTC ( [id://516637]=poem: print w/replies, xml ) Need Help??

UPDATE: Dec 19,2005 I put this to midi music in a karaoke file !! Just in time for the christmas parties. :-) See karaoke files for the midis, and the Perl scripts which generate the midi(kar) files.(Thanks to Mr. Muskrat :-) )

#!/usr/bin/perl use warnings; use strict; my @gifts = <DATA>; my @days = qw(1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th); my @dayspast; while(@days){ my $day = shift @days; push @dayspast, $day; my ($num) = $day =~ /(\d+).*/; print "On the $day day of Christmas,\nMy true Perl gave to me\n"; foreach my $gift (reverse @dayspast){ my ($n) = $gift =~ /(\d+).*/; print $gifts[$n - 1]; } print "\n"; if(scalar @dayspast == 1) {$gifts[0] = 'And '.$gifts[0]} } exit; __DATA__ a commandline in an @ARGV 2 sca-lars 3 ar-rays 4 nested hash 5 ENCODED STRINGS 6 threads-a-spawning 7 procs-a-forking 8 tests succeeding 9 modules loading 10 objects blessing 11 signals catching 12 saints-a-drinking

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re: 12 Days of Christmas
by McDarren (Abbot) on Dec 15, 2005 at 01:11 UTC
    Very nice++ :)

    Something that lends itself quite well to Perl.

    Just a couple of minor nits...

    1. If you throw a few sleeps in there, the effect is much nicer (you can almost sing along :D)
    2. There is no 'r' in 1st
    Cheers,
    Darren :)
      Ooooh. Yesterday I was told there was no 'o' in 2nd, and today, no 'r' is in 1st. Fixed.

      As far as adding sleeps to sing, I thought about it, but everyone sings at different speeds, and some people like to "drag out the 5 golden rings". So I leave tempo up to the end user. :-)


      I'm not really a human, but I play one on earth. flash japh
Re: 12 Days of Christmas
by petdance (Parson) on Dec 16, 2005 at 16:51 UTC
    Very nice. A couple of notes:
    • unshift into your past days so you don't have to reverse printing them
    • Lingua::EN::Number::Ordinate takes care of that yucky hardcoded list of day names
    Here's my shortened version
    #!/usr/bin/perl use warnings; use strict; use Lingua::EN::Numbers::Ordinate; my @past_gifts; my $day = 0; for my $todays_gift ( <DATA> ) { chomp $todays_gift; my $dayword = ordinate(++$day); print join( "\n", "On the $dayword of Christmas", "My true Perl gave to me", $todays_gift, @past_gifts, ("") x 2, ); unshift( @past_gifts, @past_gifts ? $todays_gift : "And $todays_gi +ft" ); } __DATA__ a commandline in an @ARGV 2 sca-lars 3 ar-rays 4 nested hash 5 ENCODED STRINGS 6 threads-a-spawning 7 procs-a-forking 8 tests succeeding 9 modules loading 10 objects blessing 11 signals catching 12 saints-a-drinking

    xoxo,
    Andy

Re: 12 Days of Christmas
by zentara (Archbishop) on Dec 16, 2005 at 17:35 UTC
    Nice improvement petdance! What I'm really thinking about is somehow incorporating it with MIDI::Realtime to make it a karaoke which plays the tune as it prints, with an adjustable tempo setting. :-)

    I'm not really a human, but I play one on earth. flash japh
Re: 12 Days of Christmas
by zentara (Archbishop) on Dec 19, 2005 at 18:58 UTC
    Hi, I put this into a midi (kar) file, and have the scripts to show how it's done. See the UPDATE.

    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: poem [id://516637]
Approved by ghenry
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-19 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found