in reply to KC's Sunshine (not an original poem)
One-hundred lines, same dealy-o with identical output, but inspired to minimize content by maximizing subroutine recursion. Contribution by myself, a new to perl newbie, yet seasoned programmer playing now with a headless Raspberry Pi via PuTTY on a msVista laptop. Thanks strangedoc, your example poetry helped me learn function calls and for loops, jumping ahead from Padre/absolute_beginner/05_do_it_again.pl
It contains one kludge, failing elegance, I couldn't figure out how to make the newline \n print from the word list which forced me to use "if($j==44)" (a position) along with an "else" when I'd rather instead print the 44th value "\n", but at least I'm halfway along the right track I had in mind - stripping out hard coded 'print "\n";' lines by changing them to tokens in the data stream.
#!/usr/bin/perl # Kurt Schwind: A little of KC's Sunshine # http://www.futuretg.com/FTHumanEvolutionCourse/Audio/English/KC_&_Th +e_Sunshine_Band/KC_&_The_Sunshine_Band_-_Shake_Your_Booty.mp3 use strict; use warnings; my @l = qw( a aah best booty can chance come dance do don't down duty everybody feeling feelings fight floor get give home I in it let's momma now Oh on run shake sister tell the to very well with world yeah you You your You're yourself /n); sub line { my $j = shift; while(defined $j ) { if($j==44) { print "\n"; } else { print " ".$l[$j]; } $j = shift; } } sub sh { my $sh = shift; for(1..$sh ) { line (29); } } sub yb { line (41,3,44); } sub syb { my $m = shift; for(1..$m ) { sh(1); yb(); } } sub refrain { for(1..2) { sh(6); line (44); syb(2); } line(44); } sub groove {sh(5); yb(); }; line (1,12,17,27,32,16,23,7,44,9,15,41,14,18,43,0,5,44,44); refrain(); line (1,39,4,39,4,8,22,34,35,44,42,32,2,21,32,37,20,4,31,44,44,26,44); + refrain(); line (26,38,44); sh(4); line (44,1); sh(4); line (44,44,1,44); refrain +(); line(1,44); groove(); line(1,9,15,32,13,44); groove(); line(1,18,43,0,5,44,44); groove(); line(42,4,8,22,8,22,44); groove(); line(6,19,36,24,25,44); groove(); line(44); groove(); line(1,28,10,33,30,44); sh(4); line(27,41,3,44,1,8,41,11,44); sh(4); line(44,44);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: KC's Sunshine (not an original poem)
by DisneyWizard (Initiate) on Aug 09, 2015 at 06:02 UTC |