Language Perl
(object-oriented version)
| Date: | 05/15/05 |
| Author: | Scott Bryce |
| URL: | http://scottbryce.com |
| Comments: | 1 |
| Info: | n/a |
| Score: |
#!/usr/bin/perl
use strict;
use warnings;
#######################################
#
# 99 bottles of beer on the wall
# Written in object oriented Perl
#
#######################################
my $beer = Bottles->new();
$beer->Take_One_Down() while $beer->Remaining();
package Bottles;
sub new
{
my $bottles = 99;
bless \$bottles;
}
sub Take_One_Down
{
my $self = shift;
my $s = $$self == 1 ? '' : 's';
print "$$self bottle$s of beer on the wall,\n";
print "$$self bottle$s of beer.\n";
print "Take one down, pass it around.\n";
$$self--;
$s = $$self == 1 ? '' : 's';
print "$$self bottle$s of beer on the wall.\n\n";
}
sub Remaining
{
my $self = shift;
return $$self;
}
Download Source | Write Comment
Alternative Versions
| Version | Author | Date | Comments | Rate |
|---|---|---|---|---|
| bottled by Acme::EyeDrops | Andrew Savige | 06/04/05 | 55 | |
| polyglot | Jeff Connelly | 04/20/05 | 0 | |
| Lingua::EN::Inflect | Marty Pauley | 04/20/05 | 0 | |
| bottled version | Christopher J. Carlson | 05/17/05 | 5 | |
| standard version | Jim Menard | 04/20/05 | 2 | |
| minimal version | Mark Sheppard | 06/01/05 | 1 | |
| for signature | Randolph Chung, Joey Hess | 04/20/05 | 0 | |
| BigInt | Anonymous | 04/20/05 | 0 |
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments
It shows the power of OO in Perl. The whole program is two lines and is quite readable.