Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Perl

(object-oriented version)

Date:05/15/05
Author:Scott Bryce
URL:http://scottbryce.com
Comments:1
Info:n/a
Score: (3.00 in 32 votes)
#!/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

VersionAuthorDateCommentsRate
bottled by Acme::EyeDropsAndrew Savige06/04/0576
minimal versionMark Sheppard06/01/051
bottled versionChristopher J. Carlson05/17/057
Lingua::EN::InflectMarty Pauley04/20/051
for signatureRandolph Chung, Joey Hess04/20/050
standard versionJim Menard04/20/052
polyglotJeff Connelly04/20/050
BigIntAnonymous04/20/050

Comments

>>  David said on 10/31/07 17:12:57

David Very nicely written.

It shows the power of OO in Perl. The whole program is two lines and is quite readable.

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!

Name:

eMail:

URL:

Security Code:
  
Comment: