Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to RE:(2) Automatic CODE tags by swiftone
in thread Automatic CODE tags by Odud

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-20 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found