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


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

There is now a webpage for the hack.

And

eval('0 and eval(\'def length(x) end\')'); 0 and length <<2;
has been simplified to
0 and eval('false') and length <<2;
Perl and python consider 0 false, so "0 and" is a test for ruby. There is no point in ruby actually executing length, we just need the heredoc, so we add an always failing test for ruby's false. To avoid a perl unquoted string warning, we wrap it in an eval. Which may or may not be faster than ruby actually calling a do nothing "def length(x) end" ruby function, but it avoids namespace pollution. The core concept is that the token length is serving both as a variable in a bitshift for python, and as a function with a heredoc argument for perl and ruby. The heredoc jumps over pythons """ multi-line string token, which the perl parser doesnt like. The name "length" was chosen because perl needs to have seen the function declared in order to parse the line correctly, and length() seemed innocuous. So that's the thinking behind this fragment.

Still more work to be done.

Thanks for the comments.