Hi, Monks. . . This seems like a FAQ but I'll be doggoned if I could find it anywhere. I have a script that will be taking text from a configuration file which will then be executed remotely (or locally) as a perl snippet. How can I syntax check it? eval would compile it and run it (though the stages that it completes depends on the syntax used - either of eval BLOCK or eval EXPR). E.g.:
my $str = <<'CODEIMPORT'; # this code block would be dynamic print "Don't run me!\n"; prnt 'Just check me for errors\n": CODEIMPORT # eval $str; # gives a run-time error eval { $str; }; # compiles (?) - but does not check syntax # I just want to check for syntax - # it will evaluated later and in a new/different context # (e.g., passed to a different script)
Here's a discussion from the Original Monks regarding eval in this context. Am I overlooking the obvious? I know I could shell out to perl -wc but it seems to be an overkill since I really just want to check that one little code block. I thought the B: or O: modules might help but I can't figure out how they might. Ideas?
-- Andy

In reply to Embedded Syntax Checker? by Anonymous Monk

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.