http://www.perlmonks.org?node_id=286940


in reply to Source files which work with perl, python, and ruby

This program compiles and runs under all three:
print "Hi there!\n";
results in:
[sgifford@sghome sgifford]$ perl -w /tmp/t91 Hi there! [sgifford@sghome sgifford]$ ruby -w /tmp/t91 Hi there! [sgifford@sghome sgifford]$ python /tmp/t91 Hi there!

:-)

Replies are listed 'Best First'.
Re2: Source files which work with perl, python, and ruby
by dragonchild (Archbishop) on Aug 27, 2003 at 12:51 UTC
    I believe the trick was to have the source code auto-detect which compiler was compiling it and do specific behavior as a result. In this case, the different print statements.

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.