Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Source files which work with perl, python, and ruby [webpage]

by mnc (Beadle)
on Aug 28, 2003 at 16:20 UTC ( #287430=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://287430]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2018-07-21 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (446 votes). Check out past polls.

    Notices?