Beware of that BEGIN, END, CHECK, INIT, AUTOLOAD, and DESTROY can have a sub keyword in front of them. They can also be prototyped. AUTOLOAD and DESTROY are not relevant for this post though.

However, CHECK and INIT are relevant! Try this one-liner:   perl -wle'BEGIN { require "browserUk.pl" }' where browserUk.pl is your program above, but with __END__ changed to __DATA__ (why did you use __END__ over __DATA__ anyway?), some code in DATA changed, and with a true return value:

use strict; while(<DATA>) { chomp; my $code = $_; tr/\n//d; s[((?:BEGIN|END)\s*{)][sub syntax_check_$1]g; eval 'return;' . $_; print "'$code' \n\t: ", $@ ? "Fails with\n$@" : 'Passes syntax che +ck'; } 1; __DATA__ INIT { print '*** GOTCHA!!! ***'; } # Executes. CHECK { print '*** GOTCHA!!! ***'; } # Executes. sub BEGIN { print '*** GOTCHA!!! ***'; } # Fails to compile. END () { print '*** GOTCHA!!! ***'; } # Executes. my $a = 1; my $a = cool; my $
Another issue would be to take care of use() statements as they're compile-time statements. But if you get rid of use statements, then you might also create compilation errors, since the use() statement might import prototyped subroutines. For instance, perhaps a &cool subroutine prototyped with () was imported in the code above.

And I wouldn't be surprised if there are more related issues...

ihb

In reply to Re: Re: run-time syntax checking by ihb
in thread run-time syntax checking by Pardus

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.