I recently wrote a module that extracts my Perl code from a LyX document. (LyX is a WYSIWYG LaTeX editor, if that helps provide some context.) Originally I wrote it as a source filter that was meant to be invoked on the command line, as
perl -MyX my-document.lyx
(Yes, the module is called yX.pm.) However, it'd be really cool if I could just type
perl my-document.lyx
Perl is pretty flexible, and I thought that maybe I could get away with throwing a few garbage lines at it before getting to the source filter usage line. So, I tried adding something to the LaTeX preamble, resulting in the following sort of stuff at the beginning of the .lyx file:
#LyX 2.1 created this file. For more info see http://www.lyx.org/ \lyxformat 474 \begin_document \begin_header \textclass article \begin_preamble %ignore; use yX; ...
Unfortunately, perl is not quite liberal enough:
Number found where operator expected at test.lyx line 2, near "lyxform +at 474" (Do you need to predeclare lyxformat?) Backslash found where operator expected at test.lyx line 3, near "\" (Missing semicolon on previous line?) Backslash found where operator expected at test.lyx line 4, near "begi +n_document \" (Missing semicolon on previous line?) Backslash found where operator expected at test.lyx line 5, near "begi +n_header \" (Missing semicolon on previous line?) Operator or semicolon missing before %ignore at test.lyx line 7. Ambiguous use of % resolved as operator % at test.lyx line 7. syntax error at test.lyx line 2, near "lyxformat 474" BEGIN not safe after errors--compilation aborted at test.lyx line 7.
The astute observer will notice the very top line begins with a hash character. Furthermore, LyX does not examine the content of this line, so I can change it to something like this:
#!perl -MyX
Unfortunately, Perl does not let you specify a module in the #! line. :-( Then I struck upon this discussion of the problem on the Perl Porters mailing list. Ric's solution is to use the -d switch, which would look like this:
#!perl -d:MyX
Lo! it works (after renaming the module, of course)! So my question: If I manage to create a module/extension for LyX that adds this shebang line, would I be a horrible person for exploiting this sort of hack?

In reply to Hacking a source filter into the #! line by dcmertens

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.