Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

RE: Automatic CODE tags

by Corion (Pope)
on Jun 20, 2000 at 18:52 UTC ( #19021=note: print w/ replies, xml ) Need Help??


in reply to Automatic CODE tags

I think that a very simple code-detection could already be sufficient. If the post contains something, which remotely resembles Perl code, and it dosenīt contain a single <CODE> tag, then wrap the whole post in <CODE> tags.

This is very crude, and should be toggled off in the preferences, but if you are smart enough to realize that you have user preferences, you already have learned enough about Perlmonks to know that you can use the TT><CODE> tags for your Perl code.


Comment on RE: Automatic CODE tags
RE:(2) Automatic CODE tags
by swiftone (Curate) on Jun 20, 2000 at 19:55 UTC
    I think that a very simple code-detection could already be sufficient. If the post contains something, which remotely resembles Perl code, and it dosenīt contain a single CODE tag, then wrap the whole post in CODE tags.

    A simple test would be something like:

    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.

      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.

        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.

        I thought of that, but if you are taking it line-by-line (rather than whole post), any program of more than a few lines will have plenty of lines that compile.

        $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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://19021]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (14)
As of 2014-07-30 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (239 votes), past polls