Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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; }

Comment on 99 bottles of beer on the wall
Download Code
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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2014-07-10 17:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (214 votes), past polls