99 Bottles of beer, 99 languages The goal is to write a simple "99 Bottles of Beer" program .. that is valid in at least 2 distinct languages (e.g. not Python 2 and Python 3). It must be a complete file that will run or compile.

Interesting answers should be up-voted, but compactness also counts. (Of course, language diversity is the main goal.)

EDIT: I would say that to have normal C code that does the same thing with C++ and Objective-C counts as derivative. The code should do clever stuff so that lines have different meanings with different languages.
C, Perl, PHP, Python, Ruby

Update: I've put together a jsfiddle that helps visualize the path through the code for each of the five languages: http://jsfiddle.net/wK6bD/4/embedded/result/

An alternative version, that removes all comments, and compresses all insignificant strings, regex and replacement patterns: http://jsfiddle.net/wK6bD/5/embedded/result/

And I saved a byte while I was at it. Turns out C had an unnecessary semi-colon ;)

#/*&lt;?php ob_clean();"
s='''*/include&lt;stdio.h&gt;
main($y){char*$s,$t[3],$u[3]/*';'''
def printf(a,*b):import sys;sys.stdout.write(a%b)
for y in range(99,-1,-1):
  '''
99.downto(0){|y|$y=y;"/*=;#*/;
for($y=100;$y--;){
  #/*"
  $u=(($t=$y)+99)%100;'*/
  sprintf($t,"%d",$y);sprintf($u,"%d",($y+99)%100);
  #//';#'''
  printf("%s bottle%s of beer on the wall, %s bottle%s of beer.\n%s",
    #/* -- THIS LINE ENDS WITH CR --
    y//1or'No more','s'[:y!=1],y or'no more','''s*/
    +$y&gt;0?$t:"No more",$s=$y!=1?"s":"",$y&gt;0?$t:"no more",$s,$y&gt;0?
    #//'''[:y!=1],y and'''
    "Take one down and pass it around":
    #//'''[6:38]or
    "Go to the store and buy some more");
  printf(", %s bottle%s of beer on the wall.\n\n",
    #/* -- THIS LINE ENDS WITH CR --
    y//1-1and~-y%100or'no more','''s*/
    +$y!=1?$u:"no more",$y!=2?"s":"");}
    #/*?&gt;&lt;?php "
    %w;q(*/
    }//";#'''[:y!=2])


Please Note: This file needs to be saved with mixed line endings. All lines should be terminated with LF (char 10, a.k.a. unix-style), except for the two lines marked -- THIS LINE ENDS WITH CR --, which should be terminated with CR (char 13, a.k.a. mac-style). I recommend using notepad++, or other text editor which allows you to manually edit line endings.

For PHP, it is assumed that output_buffering is enabled. According to the documentation, this is hardcoded to be Off when using the CLI, regardless of ini settings, so it needs to be explicitly (re)enabled:

$ php -d output_buffering=4096 bottles.pl.php.py.rb.c


This enables a 4kb buffer, which is the 'recommended' value. If you're using one of the supplied inis this will already be set, so it should run as-is from any web server.

The total file size is 823 bytes (not counting the comments about the line endings), an average of 164.6 bytes per language.

Versions Tested
C - gcc 4.8.1, cl 15.00
Perl - 5.16.2
PHP - 5.4.16
Python - 2.7.6, 3.3.4
Ruby - 1.8.7, 1.9.3

Output is identical for all five languages (see below).



Perl, PHP

&lt;?php '&gt;#'
;for($i='no more';100&gt;($a="$i bottle".(2^($i+=1)?'s':'').' of beer');$o="
Take one down and pass it around, $b.

".ucfirst($f="$b, $a.$o")){$b="$a on the wall";}print"$f
Go to the store and buy some more, $b.";


I like this one because of how short it is, so I'm leaving it. It also demonstrates how much of a Perl-wanna-be PHP is ;)

Sample Usage:

$ perl bottles
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.

...

2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.

1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around, no more bottles of beer on the wall.

No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.