Skip to content

Instantly share code, notes, and snippets.

@SaswatPadhi
Forked from wakhub/polyglot.pl.php.py.rb
Created June 5, 2012 03:33
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save SaswatPadhi/2872457 to your computer and use it in GitHub Desktop.
Save SaswatPadhi/2872457 to your computer and use it in GitHub Desktop.
PHP + Perl + Python + Ruby + C + C++ - polyglot
#/*<?php eval('echo "PHP Code\n";'); __halt_compiler();?> */
#include <stdio.h> /*
print ((("b" + "0" == 0) and eval('"Perl Code\n"')) or (0 and "Ruby Code\n" or "Python Code"));
__DATA__ = 1
"""""
__END__
===== . ===== */
#ifdef __cplusplus
char msg[9] = {'C','+','+',' ','C','o','d','e', '\n'};
#else
char msg[7] = {'C',' ','C','o','d','e', '\n'};
#endif
int main() { int i; for(i = 0; i < 9; ++i) putchar(msg[i]); return 0;} /*
outputs:
$ perl polyglot.pl.php.py.rb.cpp
Perl Code
$ php polyglot.pl.php.py.rb.cpp
#PHP Code
$ python polyglot.pl.php.py.rb.cpp
Python Code
$ ruby polyglot.pl.php.py.rb.cpp
Ruby Code
$ g++ -x c++ polyglot.pl.php.py.rb.cpp -o poly; ./poly
C++ Code
$ g++ -x c polyglot.pl.php.py.rb.cpp -o poly; ./poly
C Code
"""
#*/
@SaswatPadhi
Copy link
Author

@GreVer, I just added C and C++ to yours :-)

@wakhub
Copy link

wakhub commented Jun 8, 2012

Good! And I added Objective-C Code. https://gist.github.com/2895743

@ryanhaining
Copy link

0 and "Ruby Code\n" or "Python Code" this made me laugh a bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment