Hi

It's really tedious to need to correct code and example output after spotting a flaw.

That's why I just hacked PM.pl to automatically wrap code-tags around my combined source-file and output, so I just need one copy and paste.

Just put it into the same directory like your other scripts.

Activate it just with do "./PM.pl" inside your source file.

It requires a __DATA__ at the end of your source code and will warn you otherwise

NB: The do PM.pl; is omitted as is __DATA__ if it's the last line.

DEMO:
This
use v5.12; use warnings; do './PM.pl'; say for <DATA> __DATA__ 1 2 3

creates
<code> use v5.12; use warnings; say for <DATA> __DATA__ 1 2 3 </code> OUTPUT: <blockquote><i><code> 1 2 3 </code></i></blockquote>

which renders as

use v5.12; use warnings; say for <DATA> __DATA__ 1 2 3
OUTPUT:
1 2 3

PM.pl

The code is pretty self explanatory, you can adjust it to your needs

package PM; use v5.12; use warnings; use Scalar::Util qw/openhandle/; my ($pck) = caller() // __PACKAGE__; my $data = eval "\\*${pck}::DATA"; # *DATA of caller my $ctag = "code"; # avoid messup local $|=1; unless ( openhandle($data) ) { warn "__DATA__ missing, can't format source code"; } else { my $current_pos = tell $data; seek $data,0,0; say "<$ctag>"; while ( <$data> ) { print unless # ignore ... /^(do)\s.*PM/ # . do PM.pl or /^__DATA__/ && eof($data); # . __DATA__ on last line } say "</$ctag>"; seek $data,$current_pos,0; } say "OUTPUT: <blockquote><i><$ctag>"; END { say "</$ctag></i></blockquote>" }; __DATA__

UPDATE: fixed localization of non-buffering

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Helper script to format code and output to perlmonks markup by LanX

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.