Generating Perl in Other Languages
It’s easy to generate other languages in Perl, but the converse is also true. Perl can easily be generated in other languages because it’s both concise and malleable. You can pick your quotes not to interfere with the other language’s quoting mechanisms. You don’t have to worry about indentation, or where you put your line breaks, or whether to backslash your backslashes Yet Again. You aren’t forced to define a package as a single string in advance, since you can slide into your package’s namespace repeatedly, whenever you want to evaluate more code in that package.
Another thing that makes it easy to write Perl in other languages
(including Perl) is the #line
directive. Perl knows how to process these as special directives that
reconfigure its idea of the current filename and line number. This can
be useful in error or warning messages, especially for strings processed
with eval (which, when you think
about it, is just Perl writing Perl). The syntax for this mechanism is
the one used by the C preprocessor: when Perl encounters a # symbol and the word line, followed by a number and a filename, it
sets _ _LINE_ _ to the number and _ _FILE_ _ to the filename.[208]
Here are some examples that you can test by typing into perl directly. We’ve used a Control-D to indicate end-of-file, which is typical on Unix. DOS/Windows and VMS users can type Control-Z. If your shell uses something else, you’ll have to use that to tell perl you’re done. Alternatively, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access