if(Code-catcher-not-disabled){
foreach(@line-of_post){
if m?\</CODE\>?i{
{ last; }
eval { $_ }; #Actually something to do with Safe module
if not $@ {
$codify=1;
}
}
}
(Requires clean up, and has many efficency improvements that can be made, but you get the idea. Basically if there is a line (or we could set a tolerance level...say, 4 lines?) of code that will eval, it's likely perl code. THis would also catch someone who remembered the CODE tag, but not the closing tag.
Note: This should be done in a sandbox, such as the Safe module, but I haven't toyed with that enough to include it in this pseudocode.
Another option is to use one of the Perl Parsers out there to check syntax, but that involves more overhead. eval already does all the checking, and properly buried in a Safe, it shouldn't affect the exterior code at all. | [reply] [d/l] |
Of course, there should be some more logic added, as most code that gets posted, won't compile. That's why it was posted in the first place. But then again, the analyzer should simply lean more towards code than towards text, because a monospaced text is far easier to read than
vario-spaced and line-joined code.
| [reply] |
$var="bob";
eval's, even if it doesn't do much. That's why I thought the code was so nicely elegant. You don't need much logic.
| [reply] [d/l] |