Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

99 bottles of beer on the wall

by Trag (Monk)
on Apr 02, 2004 at 19:02 UTC ( #342081=poem: print w/replies, xml ) Need Help??

99 bottles of beer on the wall, 99 bottles of beer, you
take one down, pass it around, 98 bottles of beer on the
wall (please enjoy responsibly)
#!/usr/bin/perl use warnings; use strict; my $beer=99; while ($beer>0) { print "$beer bottles of beer on the wall, $beer bottles of beer\nY +ou take one down, and pass it around, $beer bottles of Beer on the wa +ll\n"; $beer--; sleep 1; }

Replies are listed 'Best First'.
Re: 99 bottles of beer on the wall
by bart (Canon) on Apr 02, 2004 at 19:38 UTC
    You didn't provide a mechanism that changes "bottles" to "bottle" when $beer==1.

    Oh, and $beer should be decremented at the moment you say "take one down".

Re: 99 bottles of beer on the wall
by corenth (Monk) on Apr 02, 2004 at 19:39 UTC
    while ($beer>0) { print "$beer bottles of beer on the wall, $beer bottles of beer\nY +ou take one down, and pass it around,"; $beer--; #got to subtract beer here!!! print "$beer bottles of Beer on the wall\n"; sleep 1; }
    Great fun!!! :)
    $state->{tired} = "true";
Re: 99 bottles of beer on the wall
by mojotoad (Monsignor) on Apr 02, 2004 at 23:24 UTC
    You'll probably be interested in node 99 Bottles Of Beer (can't we do better).

    Just cause I'm chirpy today, I'll reprise my not-very-terse solution:

    #!/usr/bin/perl $bc = abs(shift || 100); $p_sub = sub { 'Take ' . (shift == 1 ? 'it' : 'one') . " down, pass it around,\n" }; $b_sub = sub { 'bottle' . (shift != 1 ? 's' : '') }; $c_sub = sub { $_ = shift||'No'; "$_ " . &$b_sub($_) . ' of beer' }; $w_sub = sub { &$c_sub(shift) . " on the wall"; }; $sub = sub { $_ = shift; print &$w_sub($_), ",\n", &$c_sub($_), ",\n", &$p_sub($_), &$w_sub(--$_), ".\n\n" }; map(&$sub($_), reverse(1 .. $bc)); print "burp!\n";

    Matt

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: poem [id://342081]
Approved by arden
help
Chatterbox?
[Eily]: Maybe the puns in his dialogues were somehow kept through translation, but I can tell he lost his accent
[LanX]: qui?
[Eily]: Astérix
1nickt gives up on finding a Perl YAML parser that supports hash merging. In 2017.
[LanX]: Oh yes true, he lost his accent! xD
[Eily]: and since his name is a modified version of astérisque (asterisk), which is a typographical symbol, I think it's even funnier that he would lose a diacritic
[Eily]: the pun doesn't work so well with "he lost a diacritic" though :P
[LanX]: Obelix might offer to find it again ...
[LanX]: not much to translate anyway since Goscinny died
[Eily]: https://en. wikipedia.org/ wiki/List_of_Aster ix_characters some of the names were changed to include a new pun

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2017-05-24 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?