Here's a multiple-language program, or polyglot, that prints out the well-known phrase. It can be run in Perl, C (with one compiler warning), Tcl, and REBOL.
#include <stdlib.h> #include <stdio.h> #define p \ <<END set // [if 0 { ; int main() { /* }}]; puts "Hello world from Tcl!" if 0 { { */ printf("Hello world from C!\n"); return 0; } /* END ; print("Hello world from Perl!\n"); <<quit } exit REBOL [] print "Hello world from REBOL!" quit ;#*/
edit: removed an unnecessary #define, a fragment from an earlier version of the code. It was actually a somewhat cunning way to obfuscate the code, but this code isn't strictly designed just to frustrate the reader.

another edit: The "fix" broke it. It really does work now.

Replies are listed 'Best First'.
Re: Hello World in four languages... at the same time
by Mr_Person (Hermit) on Feb 10, 2003 at 22:20 UTC
    If you enjoy this sort of thing, there's a really good article by Jérôme Quelin which describes how he wrote a program that is valid on four languages: Perl, C, Befunge, and BrainF*ck. Very interesting read on how to trick the different languages into either working with each others syntax or ignoring parts of the program.
      Broken Link. Does this article still exist ?
        Oh Yeah
Re: Hello World in four languages... at the same time
by Anonymous Monk on Jan 03, 2008 at 19:33 UTC
    The quit is unnecessary in the REBOL section - don't know about the others. Cool trick though.